3

I am trying to run a code with pyaudio but some errors occured

# import library

import speech_recognition as sr
# Initialize recognizer class (for recognizing the speech)

r = sr.Recognizer()

# Reading Microphone as source
# listening the speech and store in audio_text variable

with sr.Microphone() as source:
    print("Talk")
    audio_text = r.listen(source)
    print("Time over, thanks")
    # recoginize_() method will throw a request error if the API is unreachable, hence using exception handling

    try:
        # using google speech recognition
        print("Text: " + r.recognize_google(audio_text))
    except:
        print("Sorry, I did not get that")

The errors are:

Traceback (most recent call last):
  File "C:\Users\PycharmProjects\pythonProject\venv\lib\site-packages\speech_recognition\__init__.py", line 108, in get_pyaudio
    import pyaudio
ModuleNotFoundError: No module named 'pyaudio'

 During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\PycharmProjects\pythonProject\hello_world.py", line 11, in <module>
    with sr.Microphone() as source:
  File "C:\Users\PycharmProjects\pythonProject\venv\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "C:\Users\PycharmProjects\pythonProject\venv\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

I have installed pyaudio manually with pip install PyAudio-0.2.11-cp39-cp39m-win_amd64.whl and also did curl https://bootstrap.pypa.io/ez_setup.py | python.

I tried also to install into pycharm the pyaudio but also an error raised.

C:\Users>pip freeze
comtypes==1.1.9
PyAudio @ file:///C:/Users/Downloads/PyAudio-0.2.11-cp39-cp39-win_amd64.whl


C:\Users>python -m pip install pyaudio
Requirement already satisfied: pyaudio in c:\users\appdata\local\programs\python\python39\lib\site-packages (0.2.11)
DrGenius
  • 817
  • 1
  • 9
  • 26
  • 1
    You need to make sure that the virtual environment where you run your app, is the *same* environment where you installed pyaudio. The Traceback shows it's looking for pyaudio in "*C:\Users\PycharmProjects\pythonProject\venv\lib\site-packages...*" but you installed it in "*c:\users\appdata\local\programs\python\python39\lib\site-packages*" – Gino Mempin Apr 21 '21 at 07:52
  • @GinoMempin I uninstall the module and install it again in the virtuenv that the pycharm was searching and it worked. So the point was to install it inside the project's env. – DrGenius Apr 21 '21 at 08:29

2 Answers2

1

you are using virtual environment and I guess you've installed the library for the primary virtual environment. you can fix this by recreating the virtual environment

[Edited]

as you can see, in your output for python -m pip install pyaudio you are using the primary one.

Hadi
  • 27
  • 1
  • 7
0

Have you tried pip install with the full path tothe .whl file?

pip install C:/Users/Downloads/PyAudio-0.2.11-cp39-cp39-win_amd64.whl

Make sure you use are using python 3.9 if you install cp39. I noticed you are referring to both cp37 and cp39 versions in your question.