AttributeError: module 'speech_recognition' has no attribute 'Microphone'

21 Views Asked by At

I am new to python stt, so I started with this speech_recognition library

import speech_recognition as sr


recognizer = sr.Recognizer()
with sr.Microphone() as source:
    print("Listening...")
    recognizer.adjust_for_ambient_noise(source)
    audio = recognizer.listen(source)

try:
    print("Transcribing...")
    text = recognizer.recognize_google(audio)
    print("You said:", text)
    return text
except sr.UnknownValueError:
    print("Sorry, could not understand audio.")
    return ""
except sr.RequestError as e:
    print("Error fetching results; {0}".format(e))
    return ""
I am getting this error

`----> 5 with sr.Microphone() as source:
      6     print("Listening...")
      7     recognizer.adjust_for_ambient_noise(source)

AttributeError: module 'speech_recognition' has no attribute 'Microphone'`

I tried opening up the sr directory

>>> import speech_recognition as sr
>>> dir(sr)
['AudioData', 'AudioSource', 'Microphone', 'Recognizer', 'Request', 'URLError', 'WavFile', '__author__', '__builtins__', '__cached__', '__doc__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'audioop', 'collections', 'io', 'json', 'math', 'os', 'pyaudio', 'shutil_which', 'subprocess', 'urlopen', 'wave']

I upgraded both pyaudio and speech_recognition packages

I work in an anaconda environment in jupyter notebook

0

There are 0 best solutions below