Speech recognition script not working

Hey everyone, I was trying to make a script using SpeechRecognition module. It identifies what the user tells and it prints the input

This is the script

import speech_recognition as sr 

Recognition = sr.Recognizer()

with sr.Microphone() as source:
    print("Please speak anything")
    Listener = Recognition.listen(source)

        Spoken_Text = Recognition.recognize_google(Listener)
        print("The user spoke: {}".format(Spoken_Text))
        print("Sorry could not recognize the test")

It is giving an error on line 5 that it:

with sr.Microphone() as source:

The error is:

Traceback (most recent call last):
File “c:/Users/--------/Desktop/Python projects/Speech recognition.py”, line 5, in
with sr.Microphone() as source:
File “C:\Users-----------\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition_init_.py”, line 79, in init
self.pyaudio_module = self.get_pyaudio()
File “C:\Users---------\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition_init_.py”, line 110, in get_pyaudio
raise AttributeError(“Could not find PyAudio; check installation”)
AttributeError: Could not find PyAudio; check installation
PS C:\Users------\Desktop\Python projects>

Can’t send screenshot as someone in my previous post said it is not safe to post screenshots for errors

Thanks for the help
Have a nice day/night!

Hello, @PythonBoy. As error also says, you must install the pyaudio module; because microphone input requires it. You can easily install it by typing pip install PyAudio to your terminal window.
Requirements Which Were Mentioned At SpeechRecognition · PyPI :

To use all of the functionality of the library, you should have:

  • Python 2.6, 2.7, or 3.3+ (required)
  • PyAudio 0.2.11+ (required only if you need to use microphone input, Microphone)
  • PocketSphinx (required only if you need to use the Sphinx recognizer, recognizer_instance.recognize_sphinx)
  • Google API Client Library for Python (required only if you need to use the Google Cloud Speech API, recognizer_instance.recognize_google_cloud)
  • FLAC encoder (required only if the system is not x86-based Windows/Linux/OS X)

The following requirements are optional, but can improve or extend functionality in some situations:

  • On Python 2, and only on Python 2, some functions (like recognizer_instance.recognize_bing) will run slower if you do not have Monotonic for Python 2 installed.
  • If using CMU Sphinx, you may want to install additional language packs to support languages like International French or Mandarin Chinese.

PyAudio page at PyPI : PyAudio · PyPI
Note: You don’t have to worry about these requirements if interpreter doesn’t give any error about them.

1 Like

Thanks for the help @soil. That’s what I thought that there was no error in the script but in the module, but I did not know which module was missing. Really thanks for the help! :+1: :pray:

You are welcome. I am happy to help you.

1 Like

Hey, Just on issue I tried installing it but this is the error it gives in cmd

I guess I have to update my python but I’m not sure though

Well, it seems you are too unlucky :slight_smile:. New error says “Microsoft Visual C++ 14.0 is required” and gives a link : Download Visual Studio Tools - Install Free for Windows, Mac, Linux . You can try to download it from that link

From PyAudio · PyPI, it is evident that already-built packages are available only for Python 2.7 through 3.6. If you have a later version, doing pip install pyaudio will try to build from source, which requires a build environment, which can be a challenge to set up. To avoid this, you can try downloading pyaudio from Python Extension Packages for Windows - Christoph Gohlke, which has already-built wheels for later versions of Python.

1 Like

Hey, Looks like I’m the unluckiest amongst all the users. Sure I will download it. But is there any additional setup needed to be done? or after installing it then can I use cmd?

pip install PyAudio

Thank’s for the help

You can use this command:

py -m pip install --no-index --find-links=file:///local/dir/ SomePackage
py -m pip install --no-index --find-links=/local/dir/ SomePackage
py -m pip install --no-index --find-links=relative/dir/ SomePackage


pip install some-package.whl

More info:

If you want to use virtual environment:

sinau\question-test ❯ python -m venv .venv
sinau\question-test ❯ .\.venv\Scripts\activate
sinau\question-test via 🐍 v3.10.2 (.venv) ❯ pip install .\PyAudio-0.2.11-cp310-cp310-win_amd64.whl # use file you download from Aohan Dang link
Processing d:\github\sinau\question-test\pyaudio-0.2.11-cp310-cp310-win_amd64.whl
Installing collected packages: PyAudio
Successfully installed PyAudio-0.2.11
sinau\question-test via 🐍 v3.10.2 (.venv) took 4s ❯ pip install SpeechRecognition
Collecting SpeechRecognition
  Downloading SpeechRecognition-3.8.1-py2.py3-none-any.whl (32.8 MB)
     |████████████████████████████████| 32.8 MB 726 kB/s
Installing collected packages: SpeechRecognition
Successfully installed SpeechRecognition-3.8.1
sinau\question-test via 🐍 v3.10.2 (.venv) took 39s ❯ python .\demo-speech.py
Please speak anything
Sorry could not recognize the test

Note: download the appropriate version of wheel according to your python installation
from your message, you’re using Python 3.8 so choose:

  • PyAudio‑0.2.11‑cp38‑cp38‑win_amd64.whl
  • PyAudio‑0.2.11‑cp38‑cp38‑win32.whl

Hope it will help

I tried downloading pyAudio -or just clicked the file links- at the site you linked but site raised a 404 Error.

I can download the file, maybe try other browser

I tried in another browser and yes, there is actually no problem about the site.

It seems, downloading pyAudio from the source which Aohan Dang has mentioned about is easier than downloading lots of other stuff.

True, in the past, I try to install Microsoft Build Tools, and it’s very hard to understand which tool/extension need to install. @adang1345 comment shows the easy way without you need to download other tools except the wheel itself.

Hey thanks for the help. I have downloaded what you have said. Just confirming are these the two that I can choose from?

I found this from PyPI website

Thanks for your website suggestion. I just like using PyPI for downloading modules

if your computer 64 bit download amd64
if you have 32 bit choose the later

Ok sure thanks for the help, infact my computer is 64bits I think


This is what I found on my settings about page

Hey just one problem after downloading the file and typing

pip install PyAudio

It still gave the same error.
The file is on my computer but it does not do anything

Thanks for the help so far

Then when I checked python it said its 32bit

So I downloaded 32 bits as well but did not work

But, typing pip install PyAudio says system to install PyAudio from its web source. @gunungpw has already mentioned about setting up modules via local files, in this topic. You can use any of the four methods :

py -m pip install --no-index --find-links=file:///local/dir/ SomePackage
py -m pip install --no-index --find-links=/local/dir/ SomePackage
py -m pip install --no-index --find-links=relative/dir/ SomePackage
pip install some-package.whl

One of the possible methods will seem like this:

pip install C:\Users\Joe Biden\Downloads\PyAudio-0.2.11-cp310-cp310-win_amd64.whl

The PyPI website’s pip did not work so I planned to download it from the website that @gunungpw suggested. I was just wondering which one of them to download