[英]Attribute error:module 'speech_recognition' has no attribute 'Recognizer'
I downloaded a speech recognition from pypy. 我从pypy下载了语音识别。
It was 3.6.0 version and extracted it in Lib folder inside python folder. 它是3.6.0版本,并将其提取到python文件夹内的Lib文件夹中。 Its name was something speechrecognition 3.6 and I changed it to speech_recognition and then it was not showing an error like "no such module", but inside that, there was another folder with the same name so I changed it also and now even though it has Recognizer folder it says: 它的名字叫Speechrecognition 3.6,我将其更改为Speech_recognition,然后没有显示类似“ no such module”之类的错误,但是里面有另一个同名文件夹,所以即使它已经Recognizer文件夹显示:
AttributeError: module 'speech_recognition' has no attribute 'Recognizer' AttributeError:模块“ speech_recognition”没有属性“ Recognizer”
Please help, I am new to python. 请帮助,我是python新手。
Code: 码:
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))
I had the same error and found the solution with the help of the StackOverflow community here . 我遇到了同样的错误,并在此处的StackOverflow社区的帮助下找到了解决方案。
The error was that my file name was also speech_recognition and python was checking the file instead of the library. 错误是我的文件名也是speech_recognition,而python正在检查文件而不是库。 Changing my file name solved the problem. 更改我的文件名解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.