I downloaded a speech recognition from pypy.
It was 3.6.0 version and extracted it in Lib folder inside python folder. 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:
AttributeError: module 'speech_recognition' has no attribute 'Recognizer'
Please help, I am new to 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 .
The error was that my file name was also speech_recognition and python was checking the file instead of the library. Changing my file name solved the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.