1

我不太确定这个问题的标题是什么,所以如果不能理解,我很抱歉。我一直在从事的这个项目是最近与 Jarvis 相关的项目(Python),这是我的错误

Traceback (most recent call last):
File "C:\Users\Admin\Rohan_Python\Virtual Assistant.py", line 13, in <module>
text = recog.recognize_google(sound)
File "D:\Rohan_Python\lib\site-packages\speech_recognition\__init__.py", line 858, in 
recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise 
UnknownValueError()
speech_recognition.UnknownValueError

我的代码...

             import pyttsx3 as py
             import speech_recognition as sr
             # initializing speech_recognition
             engine = py.init()
             engine.say("Hey there! I'm Trevor. A virtual assistant for 
             programmers.")
             engine.runAndWait()
             recog = sr.Recognizer()
             with sr.Microphone() as Sound_source:
             recog.energy_threshold = 10000
             recog.adjust_for_ambient_noise(Sound_source, 1.2)
             print("Listening...")
             sound = recog.listen(Sound_source)
             text = recog.recognize_google(sound)
             print(text)

我认为这可能是一个简单的错误,但有人可以解释错误的含义以及我的错误是什么吗?也请给我解决方案。请和谢谢!

4

1 回答 1

0

识别失败。您应该发现该错误:

try:
    text = recog.recognize_google(sound)
    print(text)
except sr.UnknownValueError:
    print("Could not understand")
于 2021-04-11T15:55:36.717 回答