属性错误:模块'speech_recognition'没有属性'Recognizer'

时间:2017-06-16 07:37:06

标签: python attributeerror python-3.6

我从pypy下载了一个语音识别。

它是3.6.0版本并将其解压缩到python文件夹中的Lib文件夹中。 它的名字是语音识别3.6并且我将它改为speech_recognition,然后它没有显示像“没有这样的模块”的错误,但在其中,有另一个同名的文件夹,所以我也改变了它,现在即使它有识别器文件夹,它说:

  

AttributeError:模块'speech_recognition'没有属性'Recognizer'

请帮助,我是python的新手。

代码:

import speech_recognition as sr
import pyaudio 
# Record Audio
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

# Speech recognition using Google Speech Recognition
try:
    # for testing purposes, we're just using the default API key
    # to use another API key, use `r.recognize_google(audio, 
key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
    # instead of `r.recognize_google(audio)`
    print("Speech was:" + r.recognize_google(audio, language = "en-us", 
show_all=False))
except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio") 
except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; 
{0}".format(e))

1 个答案:

答案 0 :(得分:0)

我遇到了同样的错误,并在StackOverflow社区here的帮助下找到了解决方案。

错误是我的文件名也是speech_recognition,而python正在检查文件而不是库。更改文件名即可解决问题。