【问题标题】:speech_recognition.UnknownValueError - Can someone explain this error to meSpeech_recognition.UnknownValueError - 有人可以向我解释这个错误吗
【发布时间】:2021-04-11 23:55:57
【问题描述】:

我不太确定这个问题的标题是什么,所以如果无法理解,我很抱歉。我一直在做的这个项目是最近与 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)

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

【问题讨论】:

  • 来自文档:引发 Speech_recognition.UnknownValueError 异常如果语音难以理解

标签: python-3.x speech-recognition pyttsx3


【解决方案1】:

识别失败。你应该发现这个错误:

try:
    text = recog.recognize_google(sound)
    print(text)
except sr.UnknownValueError:
    print("Could not understand")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    • 2014-10-13
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多