def convert_callback(self): if not self._file_url.get(): self._status.set("please choose audio file") elif not self._Dist_url.get(): self._status.set("please choose Destination directory") else: self._status.set("processing") self.freeze_controls() AUDIO_FILE = str(self._file_url.get()) filename = "game_log_" + datetime.datetime.now().strftime( "%Y-%m-%d_%H-%M-%S") + ".pdf" destination = self._Dist_url.get() kss = Keyword_Spotting_Service() myaudio = AudioSegment.from_file(AUDIO_FILE, "wav") chunk_length_ms = 1000 # pydub calculates in millisec chunks = make_chunks(myaudio, chunk_length_ms) # Make chunks of one sec # Export all of the individual chunks as wav files predictedSentence = "" for i, chunk in enumerate(chunks): chunk_name = "sample_AI\chunk{0}.wav".format(i) chunk.export(chunk_name, format="wav") for i, chunk in enumerate(chunks): predictedSentence += kss.predict("sample_AI\chunk" + str(i) + ".wav") + " " self._pdf = pdfkit.from_string( "prediction is: " + predictedSentence, path.join(destination, filename)) self._status.set("Log file generated!") self.unfreeze_controls()
def predict(): # get file from POST request and save it audio_file = request.files["file"] file_name = str(random.randint(0, 100000)) audio_file.save(file_name) # instantiate keyword spotting service singleton and get prediction kss = Keyword_Spotting_Service() predicted_keyword = kss.predict(file_name) # we don't need the audio file any more - let's delete it! os.remove(file_name) # send back result as a json file result = {"keyword": predicted_keyword} return jsonify(result)
def predict(): audio_file = request.files["file"] file_name = str(random.randint(0, 100000)) audio_file.save(file_name) kss = Keyword_Spotting_Service() predicted_keyword = kss.predict(file_name) os.remove(file_name) data = {"keyword": predicted_keyword} return jsonify(data)
def main_func(file): list_text = [] dangerous_word = 'left' convert_audio_format(file) main_dir = file.replace('ogg', 'wav') Preprocess_Signal(main_dir) files = order_files_by(main_dir) kss = Keyword_Spotting_Service() for i in range(len(files)): list_text.append(kss.predict(files[i])) print(list_text) for j in range(len(list_text)): if list_text[j] == dangerous_word: alert_massage()
def predict(): # get audio file and save it audio_file = request.files["file"] file_name = str(random.randint(0, 1000000)) audio_file.save(file_name) # invoke keyword spotting service kss = Keyword_Spotting_Service() # make a prediction predicted_keyword = kss.predict(file_name) # remove de audio file os.remove(file_name) # send back the predicted keyword to the client data = {"keyword": predicted_keyword} return jsonify(data)
def predict(): # Get audio file and save it audio_file = request.files["file"] file_name = str(random.randint(0, 100000)) audio_file.save(file_name) # Invoke keyword spotting service kss = Keyword_Spotting_Service() # Make a prediction predicted_keyword = kss.predict(file_name) # Remove the audio file os.remove(file_name) # Send back the predicted Keyword in Json format data = {"keyword": predicted_keyword} return jsonify(data)
def predict(): """Endpoint to predict keyword :return (json): This endpoint returns a json file with the following format: { "keyword": "down" } """ # get file from POST request and save it audio_file = request.files["file"] file_name = str(random.randint(0, 100000)) audio_file.save(file_name) # instantiate keyword spotting service singleton and get prediction kss = Keyword_Spotting_Service() predicted_keyword = kss.predict(file_name) # we don't need the audio file any more - let's delete it! os.remove(file_name) # send back result as a json file result = {"keyword": predicted_keyword.split("\\")[-1]} return jsonify(result)