我希望获得一个有效的简单语音识别。我一直在看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))
现在它的工作完美!!!
关于python - Python 3.4的语音识别功能简单易行吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33934930/