我正在开发一个虚拟助手。我正在使用google_speech_to_text转换器我无法继续保持音频输入。我想如果有任何方法我可以使用两个环境,一个将用于监听和转换文本,其他将用于其余的处理。
我不想改变我的STT引擎。我只是想知道是否可以在环境之间同时切换。如果是的话,怎么样?
这是我的input.py文件:我需要接收音频输入我调用函数start_listening()
:
import speech_recognition as sr
import output
import winsound
def start_listening():
r = sr.Recognizer()
with sr.Microphone() as source:
# output.speak("Listening")
r.adjust_for_ambient_noise(source)
audio = r.record(source, duration=5)
try:
return r.recognize_google(audio)
except:
output.speak("Unable to Translate, speak again")
start_listening()
这是我的processing.py文件:
import input as listener
import output as speak
import clock
import query_processor as mind
import rideBooking
#First Greeting at the startup , according to the time select the greeting
speak.speak(clock.get_part_of_day())
def searching_for_word(word,sentence):
if word in sentence:
return True
else:
return False
def main_organ():
input = listener.start_listening()
inputType = mind.classify(input)
if inputType == 'whatever':
#run different functions on different commands
main_organ()
#run the app with the below code
if __name__ == "__main__":
main_organ()
当处理开启时,应用程序无法收听。它只能在处理完全完成时start_liste。
您可以创建多个进程。
为此,请导入multiprocessing.Process.run
模块和recover the return value。
您可以使用queue处理来自子进程的数据。
您不需要多个环境。