Python 3.4的语音识别是否容易操作?

2024-04-28 19:38:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望得到一个简单的语音识别工作。我在语音识别上一直在看这个,当我执行代码时,发生了以下错误

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")

这是从他们网页上的例子中抄来的


Tags: 代码importyousourceas错误语音audio
3条回答

你使用什么版本的语音识别库?

您可以通过以下方式查看:

import speech_recognition as sr
print sr.__version__

如果您使用的是最新版本(SpeechRecognition 3.1.3),那么应该使用recognize_google()方法而不是recognize()来使用Google API。

至于最新的文档,您可以查一下here,也可以查一些有用的examples

我也面临同样的问题。问题是我没有设置最低阈值。所以我添加了这个代码。

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))

现在它的工作完美!!!

我成功了。

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

print(r.recognize_google(audio))

相关问题 更多 >