Python 属性错误:模块';语音识别&x27;没有属性';识别器';
我从pypy下载了一个语音识别 它是3.6.0版本,并将其解压缩到python文件夹中的Lib文件夹中。 它的名字是speechrecognition 3.6,我将它改为speech_recognition,然后它没有显示类似“无此模块”的错误,但在它里面,有另一个同名文件夹,所以我也对它进行了更改,现在即使它有识别器文件夹,它也会说: AttributeError:模块“语音识别”没有属性“识别器” 请帮忙,我是python新手 代码:Python 属性错误:模块';语音识别&x27;没有属性';识别器';,python,attributeerror,python-3.6,Python,Attributeerror,Python 3.6,我从pypy下载了一个语音识别 它是3.6.0版本,并将其解压缩到python文件夹中的Lib文件夹中。 它的名字是speechrecognition 3.6,我将它改为speech_recognition,然后它没有显示类似“无此模块”的错误,但在它里面,有另一个同名文件夹,所以我也对它进行了更改,现在即使它有识别器文件夹,它也会说: AttributeError:模块“语音识别”没有属性“识别器” 请帮忙,我是python新手 代码: 我也犯了同样的错误,在StackOverflow社区的帮
我也犯了同样的错误,在StackOverflow社区的帮助下找到了解决方案
错误是我的文件名也是speech_recognition,python检查的是文件而不是库。更改我的文件名解决了这个问题。更改库的随机名称时,您还希望看到什么?我认为预期的设置过程不需要手动重命名两个文件夹。您是否尝试过遵循?我更改了名称,因为没有名为speech recognition的模块显示错误。请告诉我在Lib文件夹中提取模块后应该做什么
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))