我希望得到一个简单有效的语音识别。我一直在 speech_recognition 上查看这个,当我执行代码时出现以下错误
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
try:
print("You said " + r.recognize(audio))
except LookupError:
print("You said " + r.recognize(audio)) # recognize speech using Google Speech Recognition
AttributeError: 'Recognizer' object has no attribute 'recognize'
print("Could not understand audio")
这是从他们网页上的例子复制过来的
请您参考如下方法:
我遇到了同样的问题。问题是我没有设置最低阈值水平。所以我添加了这段代码。
import speech_recognition as sr
r = sr.Recognizer()
m = sr.Microphone()
#set threhold level
with m as source: r.adjust_for_ambient_noise(source)
print("Set minimum energy threshold to {}".format(r.energy_threshold))
# obtain audio from the microphone
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
print(r.recognize_google(audio))
现在一切正常!!!
