Speech recognition google语音识别总是在出现UnknownValueError后终止程序 程序在引发UnknownValueError后崩溃
我试图继续通过应用程序,但当出现此UnknownValueError时,会终止/结束整个程序。如果sr.UnknownValueError不终止程序,我将如何使用它?事实上,我曾经让它在某一点上工作过,但它似乎在代码未被触摸或编辑的情况下就停止了工作。我将感谢您提供的任何帮助。谢谢 这是我的密码:Speech recognition google语音识别总是在出现UnknownValueError后终止程序 程序在引发UnknownValueError后崩溃,speech-recognition,speech,google-speech-api,Speech Recognition,Speech,Google Speech Api,我试图继续通过应用程序,但当出现此UnknownValueError时,会终止/结束整个程序。如果sr.UnknownValueError不终止程序,我将如何使用它?事实上,我曾经让它在某一点上工作过,但它似乎在代码未被触摸或编辑的情况下就停止了工作。我将感谢您提供的任何帮助。谢谢 这是我的密码: while speakCommand == True: # GOOGLE LISTEN print ("Please speak a command.") engine =
while speakCommand == True:
# GOOGLE LISTEN
print ("Please speak a command.")
engine = pyttsx.init()
engine.say("Please speak a command.")
engine.runAndWait()
# r.record(source, duration = 60s, offset = None)
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source, timeout=None)
VoiceCommand1Up = r.recognize_google(audio)
VoiceCommand1Low = (VoiceCommand1Up.lower())
try:
print("You said, " + r.recognize_google(audio))
# engine = pyttsx.init()
# engine.say("We think you said, " + VoiceCommand1Low)
# engine.runAndWait()
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
engine = pyttsx.init()
engine.say("Google Speech Recognition could not understand audio")
engine.runAndWait()
standby = False
speakCommand = True
break
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
engine = pyttsx.init()
engine.say("Could not request results from Google Speech Recognition service; {0}".format(e))
engine.runAndWait()
standby = False
speakCommand = True
break