Search code examples
pythonspeech-recognitionpyaudio

My personel Assistants project : AttributeError: Could not find PyAudio; check installation


I'm trying to make a personel assistant. When I run the code, the code works, it says what it should say at the beginning, but when it comes to the line of code I've shown below, it throws an error. Here is that error

    Traceback (most recent call last):
  File "C:\Users\Koray\AppData\Local\Programs\Python\Python310\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\Koray\Desktop\Çalışmalar\Python\Jarvis\main.py", line 60, in <module>
    query = takeCommand().lower()
  File "C:\Users\Koray\Desktop\Çalışmalar\Python\Jarvis\main.py", line 33, in takeCommand
    with speech_recognition.Microphone() as source:
  File "C:\Users\Koray\AppData\Local\Programs\Python\Python310\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "C:\Users\Koray\AppData\Local\Programs\Python\Python310\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 try to pip install pyaudio but then this error show up:

    Collecting pyaudio
  Downloading PyAudio-0.2.11.tar.gz (37 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.10
      copying src\pyaudio.py -> build\lib.win-amd64-3.10
      running build_ext
      building '_portaudio' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyaudio
  Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
  Running setup.py install for pyaudio ... error
  error: subprocess-exited-with-error

  × Running setup.py install for pyaudio did not run successfully.
  │ exit code: 1
  ╰─> [9 lines of output]
      running install
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.10
      copying src\pyaudio.py -> build\lib.win-amd64-3.10
      running build_ext
      building '_portaudio' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pyaudio

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

This is my code:

def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
    print("Listening...")
    r.pause_threshold = 1
    audio = r.listen(source)

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

except Exception as e:
    speak("Say that again please...")
    return "None"
return query

Please can you help me?


Solution

  • there have two possible solution for solving this problem

    1st solution:

    pip install pipwin
    

    then

    pipwin install pyaudio
    

    2nd solution:

    sudo apt-get install portaudio19-dev python-pyaudio
    

    then

    pip install PyAudio