ModuleNotFoundError: No module named 'speech_recognition' (windows COMPUTER)

My installation command was:

pip install speechrecognition
pip install pyAudio

In my file it raise this error:

Traceback (most recent call last):
  File "e:/Projects/Python/Assistant/main.py", line 1, in <module>
    import speech_recognition as sr
ModuleNotFoundError: No module named 'speech_recognition'

And my code was:

import speech_recognition as sr

Upvotes: 1

Views: 5087

Answers (3)

I had the same issue. Using Visual Studio Code. Found out that my python interpreter was looking at the wrong virtual environment. I changed the location using control + shift + P to the location of my current files that I installed speech recognition. I am using version 3.9 by the way.

Upvotes: 1

Redgar Tech
Redgar Tech

Reputation: 365

As said earlier, the correct command is pip install SpeechRecognition and then import like so... import speech_recognition as sr then when ready to use it, implement it like this...

def takeCommand():
    r = sr.Recognizer()

    with sr.Microphone() as source:

        print("Listening...")
        r.pause_threshold = .5
        audio = r.listen(source)

    try:
        print("Recognizing...")
        query = r.recognize_google(audio, language='en-us')
        print("User said: {query}\n")

    except Exception as e:
        print(e)
        print("Unable to understand.")
        return "None"

    return query

You want to make sure that exception handler is in there. This is done from documentation.

EDIT

The issue may also be the version of Python. SpeechRecognition isn't supported for Python 3.7 and above. I tested it for Python 3.6 and it worked perfectly. They do need to release a working version for the newer Python versions.

Upvotes: 1

I fixed my bug! I don't know what the error was but it's fixed!

Upvotes: 0

Related Questions