我实际上是NLI(Novitatis Locus Industries)的成员,我们的团队似乎遇到了一些问题。在使用GUI设计启用语音的程序时,tkinter的mainloop似乎给了我们一些问题。查看我们的代码-
//this function defines the gui//
def gui():
gui_kurooto = Tk()
txt_dsply_var = StringVar()
AUTHN_LBL = Label(gui_kurooto, text=txt_dsply_var)
AUTHN_LBL.pack()
gui_kurooto.mainloop()
//this code defines the microphone input//
def takeCommand():
#It takes microphone input from the user and returns string output
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
txt_dsply_var = StringVar()
txt_dsply_var.set('Listening')//display listening on gui//
r.pause_threshold = 1
r.energy_threshold = 10000
audio = r.listen(source)
try:
print("Recognizing...")
txt_dsply_var = StringVar()
txt_dsply_var.set('Recognizing')//display recognizing//
query = r.recognize_google(audio, language='en-en')
print(f"User said: {query}\n")
txt_dsply_var = StringVar()
txt_dsply_var.set(f"User said: {query}\n")//display input//
except Exception as e:
# print(e)
print("Say that again please...")
return "None"
return query
//to run//
if __name__ == "__main__":
gui()
while True:
# if 1:
query = takeCommand().lower()
现在,当我尝试运行此代码时,代码永远不会到达while循环。我知道mainloop是一个无限循环,但是有替代品可以帮助我实现其他功能。使功能无法正常运行也不起作用。我可以将其放在查询命令之后吗?
我还有另一个问题,有没有一种方法可以根据语音输入来频谱分析,例如Google和Siri会在我们讲话时移动呢?
任何帮助将不胜感激。