def main_function(in_path, file_name): start = time.time() dir_name = file_name + "_dir" if os.path.exists(dir_name): os.chdir(dir_name) else: os.makedirs(dir_name) #os.chdir(dir_name) print("Directory does not exits!! Created the directory") try: convert_to_mp3(in_path, file_name, dir_name) except Exception as e: print("could not convert to mp3") print(e) sys.exit(1) print("Converted to mp3 successfully") os.chdir(dir_name) try: mp4_file_name = file_name + ".mp3" convert_to_wav(mp4_file_name) except Exception as e: print("could not convert to wav") print(e) sys.exit(1) print("Converted to wav successfully") mp4_file_name = file_name + ".mp3" try: chunks_dir_name = file_name + "_chunks" wav_file_name = mp4_file_name + ".wav" vd.convert_to_chunks(wav_file_name, 2, chunks_dir_name) except Exception as e: print("could not convert to chunks") print(e) sys.exit(1) print("Conversion to chunks successful") try: print(chunks_dir_name) wst.speech_to_text(chunks_dir_name) except Exception as e: print("could not translate chunks") print(e) sys.exit(1) print("Translation to chunks successful") try: questions_svm.train_test("../train_1.csv", chunks_dir_name + "/res_file_question.csv", "classification.csv") except Exception as e: print("Question classification does not work") print(e) sys.exit(1) try: list_sen.list_sentences("classification.csv", "list_of_questions.csv") except Exception as e: print("Listing questions does not work") print(e) sys.exit(1) try: srq.search_for_relvant_questions("../keywords.txt", "list_of_questions.csv", "../questions_results.csv", file_name) except Exception as e: print("Searching for relvant questions does not work") print(e) #return 1 sys.exit(1) try: wav_file_name = mp4_file_name + ".wav" sa.split(wav_file_name, mp4_file_name + '_laugh_chunks') except Exception as e: print("could not split the video") print(e) #sys.exit(1) return 1 try: #print(os.getcwd()) os.chdir('..') print(mp4_file_name + '_dir') x = 'python2 pyAudioAnalysis/audioAnalysis.py classifyFolder -i ' + dir_name + '/' + mp4_file_name + '_dir' + ' --model svm --classifier svm1 > ' + dir_name + '/laugh_result' print(x) os.system(x) except Exception as e: print("could not execute cmd") print(e) #sys.exit(1) return 1 print("laughter detected") try: rs.remove_space(dir_name, 'laugh_result', file_name) except Exception as e: print("Could not rename") print(e) #sys.exit(1) return 1 print("result written csv") try: os.chdir('OpenVokaturi/examples') detect_emotion('../../' + dir_name, wav_file_name, "emotion_results.csv") os.chdir("../..") except Exception as e: print("Emotion detection did not work") print(e) #sys.exit(1) return 1 print("Emotion detection worked!!") end = time.time() os.chdir("..") print("Total time of execution: ", end - start, "seconds")
def main_function(in_path, file_name): start = time.time() dir_name = file_name + "_dir" if os.path.exists(dir_name): os.chdir(dir_name) else: os.makedirs(dir_name) #os.chdir(dir_name) print("Directory does not exits!! Created the directory") try: convert_to_mp3(in_path, file_name, dir_name) except Exception as e: print("could not convert to mp3") print(e) sys.exit(1) print("Converted to mp3 successfully") os.chdir(dir_name) try: mp4_file_name = file_name + ".mp3" convert_to_wav(mp4_file_name) except Exception as e: print("could not convert to wav") print(e) sys.exit(1) print("Converted to wav successfully") mp4_file_name = file_name + ".mp3" try: chunks_dir_name = file_name + "_chunks" wav_file_name = mp4_file_name + ".wav" vd.convert_to_chunks(wav_file_name, 2, chunks_dir_name) except Exception as e: print("could not convert to chunks") print(e) sys.exit(1) print("Conversion to chunks successful") try: print(chunks_dir_name) wst.speech_to_text(chunks_dir_name) except Exception as e: print("could not translate chunks") print(e) sys.exit(1) print("Translation to chunks successful") try: questions_svm.train_test("../train_1.csv", chunks_dir_name + "/res_file_question.csv", "classification.csv") except Exception as e: print("Question classification does not work") print(e) sys.exit(1) try: list_sen.list_sentences("classification.csv", "list_of_questions.csv") except Exception as e: print("Listing questions does not work") print(e) sys.exit(1) try: srq.search_for_relvant_questions("../keywords.txt", "list_of_questions.csv", "../questions_results.csv", file_name) except Exception as e: print("Searching for relvant questions does not work") print(e) return 1 #sys.exit(1) end = time.time() os.chdir("..") print("Total time of execution: ", end - start, "seconds")
def main_function(in_path, file_name): result_list = ['actual name', file_name] start = time.time() dir_name = file_name + "_dir" if os.path.exists(dir_name): os.chdir(dir_name) else: os.makedirs(dir_name) #os.chdir(dir_name) print("Directory does not exits!! Created the directory") try: convert_to_mp3(in_path, file_name, dir_name) except Exception as e: print("could not convert to mp3") print(e) #sys.exit(1) #return 1 return {"status": "error"} print("Converted to mp3 successfully") os.chdir(dir_name) try: mp4_file_name = file_name + ".mp3" convert_to_wav(mp4_file_name) return {"status": "error"} except Exception as e: print("could not convert to wav") print(e) #sys.exit(1) return {"status": "error"} print("Converted to wav successfully") mp4_file_name = file_name + ".mp3" try: chunks_dir_name = file_name + "_chunks" wav_file_name = mp4_file_name + ".wav" vd.convert_to_chunks(wav_file_name, 2, chunks_dir_name) except Exception as e: print("could not convert to chunks") print(e) #sys.exit(1) return {"status": "error"} print("Conversion to chunks successful") try: print(chunks_dir_name) wst.speech_to_text(chunks_dir_name) except Exception as e: print("could not translate chunks") print(e) #sys.exit(1) return {"status": "error"} print("Translation to chunks successful") try: questions_svm.train_test("../train_1.csv", chunks_dir_name + "/res_file_question.csv", "classification.csv") except Exception as e: print("Question classification does not work") print(e) #sys.exit(1) return {"status": "error"} try: list_sen.list_sentences("classification.csv", "list_of_questions.csv") except Exception as e: print("Listing questions does not work") print(e) #sys.exit(1) return {"status": "error"} try: q_res = srq.search_for_relvant_questions("../keywords.txt", "list_of_questions.csv", "../questions_results.csv", file_name) result_list.extend(q_res) except Exception as e: print("Searching for relvant questions does not work") print(e) return {"status": "error"} #sys.exit(1) try: wav_file_name = mp4_file_name + ".wav" sa.split(wav_file_name, mp4_file_name + '_laugh_chunks') except Exception as e: print("could not split the video") print(e) #sys.exit(1) return {"status": "error"} try: #print(os.getcwd()) os.chdir('..') print(mp4_file_name + '_dir') x = 'python2 pyAudioAnalysis/audioAnalysis.py classifyFolder -i ' + dir_name + '/' + mp4_file_name + '_laugh_chunks' + ' --model svm --classifier svm1 > ' + dir_name + '/laugh_result' print(x) os.system(x) except Exception as e: print("could not execute cmd") print(e) #sys.exit(1) return {"status": "error"} print("laughter detected") try: l_res = rs.remove_space(dir_name, 'laugh_result', file_name) result_list.extend(l_res) except Exception as e: print("Could not rename") print(e) #sys.exit(1) return {"status": "error"} print("result written csv") try: os.chdir('OpenVokaturi/examples') e_res = detect_emotion('../../' + dir_name, wav_file_name, "emotion_results.csv") result_list.extend(e_res) os.chdir("../..") except Exception as e: print("Emotion detection did not work") print(e) return {"status": "error"} print("Emotion detection worked!!") print(os.getcwd()) try: rsp_res = rsp.pitch_rate_amplitude(dir_name, 'pitch_results.csv') result_list.extend(rsp_res) except Exception as e: print("Could not execute pitch") print(e) return {"status": "error"} end = time.time() print('result list: ', result_list) os.chdir("..") result_list[0] = result_list[0].split('.')[0] + '_2' + '.mp4' rel_questions = result_list.pop(2) result_list.append(-1) result_list.append(rel_questions) json_res = { 'questions': result_list[2], 'relevant-questions': result_list[15], 'laughter': result_list[3], 'Neutral': result_list[4], 'Happy': result_list[5], 'Sad': result_list[6], 'Angry': result_list[7], 'Fear': result_list[8], 'avg_speed': result_list[9], 'avg_pitchrange': result_list[10], 'amplitude1': result_list[12], 'amplitude2': result_list[12], 'amplitude3': result_list[13], } print("Total time of execution: ", end - start, "seconds") return json_res
def main_function(in_path, file_name): result_list = ['actual name', file_name] start = time.time() dir_name = file_name + "_dir" if os.path.exists(dir_name): os.chdir(dir_name) else: os.makedirs(dir_name) os.chdir(dir_name) print("Directory does not exits!! Created the directory") try: sc.get_shots('../' + in_path + '/' + file_name) except Exception as e: print(e) return {"status": "error"} print("SCREENSHOT DONE") try: x = my_board.board() print(x) except Exception as e: print(e) return {"status": "error"} print("board value: ", x) os.chdir('..') try: convert_to_mp3(in_path, file_name, dir_name) except Exception as e: print("could not convert to mp3") print(e) #sys.exit(1) #return 1 return {"status": "error"} print(os.getcwd()) os.chdir(dir_name) print("Converted to mp3 successfully") try: print("ABC") mp4_file_name = file_name + ".mp3" convert_to_wav(mp4_file_name) print("ABC") except Exception as e: print("could not convert to wav") print(e) #sys.exit(1) return {"status": "error"} print("Converted to wav successfully") mp4_file_name = file_name + ".mp3" try: chunks_dir_name = file_name + "_chunks" wav_file_name = mp4_file_name + ".wav" vd.convert_to_chunks(wav_file_name, 2, chunks_dir_name) except Exception as e: print("could not convert to chunks") print(e) #sys.exit(1) return {"status": "error"} print("Conversion to chunks successful") try: print(chunks_dir_name) wst.speech_to_text(chunks_dir_name) except Exception as e: print("could not translate chunks") print(e) #sys.exit(1) return {"status": "error"} print("Translation to chunks successful") try: questions_svm.train_test("../train_1.csv", chunks_dir_name + "/res_file_question.csv", "classification.csv") except Exception as e: print("Question classification does not work") print(e) #sys.exit(1) return {"status": "error"} try: list_sen.list_sentences("classification.csv", "list_of_questions.csv") except Exception as e: print("Listing questions does not work") print(e) #sys.exit(1) return {"status": "error"} try: q_res = srq.search_for_relvant_questions("../keywords.txt", "list_of_questions.csv", "../questions_results.csv", file_name) result_list.extend(q_res) except Exception as e: print("Searching for relvant questions does not work") print(e) return {"status": "error"} #sys.exit(1) try: wav_file_name = mp4_file_name + ".wav" sa.split(wav_file_name, mp4_file_name + '_laugh_chunks') except Exception as e: print("could not split the video") print(e) #sys.exit(1) return {"status": "error"} try: #print(os.getcwd()) os.chdir('..') print(mp4_file_name + '_dir') z = 'python2 pyAudioAnalysis/audioAnalysis.py classifyFolder -i ' + dir_name + '/' + mp4_file_name + '_laugh_chunks' + ' --model svm --classifier svm1 > ' + dir_name + '/laugh_result' print(z) os.system(z) except Exception as e: print("could not execute cmd") print(e) #sys.exit(1) return {"status": "error"} print("laughter detected") try: l_res = rs.remove_space(dir_name, 'laugh_result', file_name) result_list.extend(l_res) except Exception as e: print("Could not rename") print(e) #sys.exit(1) return {"status": "error"} print("result written csv") try: os.chdir('OpenVokaturi/examples') e_res = detect_emotion('../../' + dir_name, wav_file_name, "emotion_results.csv") result_list.extend(e_res) os.chdir("../..") except Exception as e: print("Emotion detection did not work") print(e) return {"status": "error"} print("Emotion detection worked!!") print(os.getcwd()) try: rsp_res = rsp.pitch_rate_amplitude(dir_name, 'pitch_results.csv') result_list.extend(rsp_res) except Exception as e: print("Could not execute pitch") print(e) return {"status": "error"} end = time.time() print('result list: ', result_list) os.chdir("..") result_list[0] = result_list[0].split('.')[0] + '_2' + '.mp4' rel_questions = result_list.pop(3) result_list.append(x) result_list.append(-1) result_list.append(rel_questions) result_list.pop(4) result_list[3] = int(result_list[3]) '''json_res = { 'questions':result_list[2], 'relevant-questions':result_list[16], 'laughter':result_list[3], 'Neutral':result_list[4], 'Happy':result_list[5], 'Sad':result_list[6], 'Angry':result_list[7], 'Fear':result_list[8], 'avg_speed':result_list[9], 'avg_pitchrange': result_list[10], 'amplitude1':result_list[12], 'amplitude2':result_list[12], 'amplitude3':result_list[13], 'board_usage':result_list[14] }''' print(result_list) #print(json_res) #print("Total time of execution: ",end - start,"seconds") #return json_res try: final_score = mm.predict_value(result_list) except Exception as e: print("Could not find final score") print(e) return {"status": "error"} try: questions_score = qq.predict_value(result_list) except Exception as e: print("Could not find questions score") print(e) return {"status": "error"} try: ros_score = ros.predict_value(result_list) except Exception as e: print("Could not find rate of speech score") print(e) return {"status": "error"} try: amp_score = am.predict_value(result_list) except Exception as e: print("Could not find aplitude score") print(e) return {"status": "error"} try: pitch_score = pi.predict_value(result_list) except Exception as e: print("Could not find pitch score") print(e) return {"status": "error"} try: laughter_score = la.predict_value(result_list) except Exception as e: print("Could not find laughter score") print(e) return {"status": "error"} try: mood_score = mo.predict_value(result_list) except Exception as e: print("Could not find mood score") print(e) return {"status": "error"} try: board_score = mo.predict_value(result_list) except Exception as e: print("Could not find board score") print(e) return {"status": "error"} scores = [ questions_score, laughter_score, mood_score, ros_score, pitch_score, amp_score, board_score ] result_list[15] = final_score new_res_list = result_list[2:] print("SCORES: ", scores) print("FINAL LIST: ", new_res_list) try: sug = suggestion.scoresToText(new_res_list, scores) except Exception as e: print("Could not find suggestions") print(e) return {"status": "error"} print("SUGGESSIONS") print(sug) sug = json.loads(sug) json_res = { 'questions': result_list[2], 'relevantQuestions': result_list[16], 'laughter': result_list[3], 'Neutral': result_list[4], 'Happy': result_list[5], 'Sad': result_list[6], 'Angry': result_list[7], 'Fear': result_list[8], 'avgSpeed': result_list[9], 'avgPitchrange': result_list[10], 'amplitude1': result_list[12], 'amplitude2': result_list[12], 'amplitude3': result_list[13], 'boardUsage': result_list[14], 'questionsScore': int(questions_score), 'laughterScore': int(laughter_score), 'moodScore': int(mood_score), 'avgSpeedScore': int(ros_score), 'pitchScore': int(pitch_score), 'amplitudeScore': int(amp_score), 'boardScore': int(board_score), 'finalScore': int(final_score), 'questionsSuggestion': sug['Questions'], 'laughterSuggestion': sug['Laughter'], 'moodSuggestion': sug['Mood'], 'avgSpeedSuggestion': sug['Rateofspeech'], 'pitchSuggestion': sug['Pitch'], 'amplitudeSuggestion': sug['Amplitude'], 'boardSuggestion': sug['Board'], } print("FINAL JSON") print(json_res) print("FINAL DIR: ", os.getcwd()) new_file_name = file_name + '_json' final_json = json.dumps(json_res) with open("result_jsons/" + new_file_name, "w+") as f: f.write(final_json) #f = open('result_json/'+new_file_name, 'w+') #f.write(final_json) print("Total time of execution: ", end - start, "seconds") return json_res