mohaker
mohaker

Reputation: 13

Could not find PyAudio; check installation

I am working on a Python project which needs PyAudio, This is the code bellow:

import pyttsx3
import speech_recognition as sr
import os
def take_commands():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Listening')
        r.pause_threshold = 0.7
        audio = r.listen(source)
        try:
            print("Recognizing")
            Query = r.recognize_google(audio)
            print("the query is printed='", Query, "'")
        except Exception as e:
            print(e)
            print("Say that again sir")
            return "None"
    import time
    time.sleep(2)
    return Query

def Speak(audio):
    engine = pyttsx3.init()
    engine.say(audio)
    engine.runAndWait()

Speak("Do you want to shutdown your computer sir?")
while True:
    command = take_commands()
    if "no" in command:
        Speak("Thank u sir I will not shut down the computer")
        break
    if "yes" in command:
        # Shutting down
        Speak("Shutting the computer")
        os.system("shutdown /s /t 30")
        break
    Speak("Say that again sir")

I couldn't add PyAudio in Python interpreter at first, so I installed it by pip install pyaudio and conda install pyaudio. I faced errors and first but finally I solved it, and finally I was able to add PyAudio from Python interpreter. however, I am still unable to import pyaudio, when I run my code I get this error:

Traceback (most recent call last):
  File "C:\Users\moham\PycharmProjects\rich\venv\lib\site-packages\speech_recognition\__init__.py", line 107, 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\moham\OneDrive\الصور\Screenshots\ig-followers-master\shutdown.py", line 50, in <module>
    command = take_commands()
  File "C:\Users\moham\OneDrive\الصور\Screenshots\ig-followers-master\shutdown.py", line 17, in take_commands
    with sr.Microphone() as source:
  File "C:\Users\moham\PycharmProjects\rich\venv\lib\site-packages\speech_recognition\__init__.py", line 79, in __init__
    self.pyaudio_module = self.get_pyaudio()
  File "C:\Users\moham\PycharmProjects\rich\venv\lib\site-packages\speech_recognition\__init__.py", line 109, in get_pyaudio
    raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
So my question: "Will the error disappear if I imported PyAudio, if yes how could I?"

Upvotes: 0

Views: 4298

Answers (4)

anon
anon

Reputation:

For the installation of pyaudio under windows, try this: https://stackoverflow.com/a/55947519/10770878

I was only able to get PyAudio working with the help of pipwin as suggested in the linked comment by Tomi Aarnio.

Upvotes: 0

Revanth
Revanth

Reputation: 26

Try this: First uninstall PyAudio using command pip uninstall pyaudio Second reinstall it again by using pip install PyAudio Sorry if this didn't work. You are welcome if it worked.

Upvotes: 1

Shivam Pawar
Shivam Pawar

Reputation: 141

In your system, there might be more than one versions of python available. There are two ways to fix this problem:

  1. Keep only one version installed and remove all other. In some cases pip install command install packages in different version of python and we are working on different version that's why this type of error occur. After that you can install your package again.
pip install pyaudio
  1. If you want to keep other version installed, then try this:
    • check which interpreter of python is used by PyCharm. You can find your interpreter here: File > Settings > Project > Python Interpreter for Windows and Linux system.
    • note the version of python for example it is 3.8 then try to install your package with is command:
py -3.8 -m pip install pyaudio

Upvotes: 0

Leemosh
Leemosh

Reputation: 905

I think I had to install pyaudio manually from https://www.lfd.uci.edu/~gohlke/pythonlibs/ when I was working with pyaudio. Check your version of python, download and install the version you need.

Upvotes: 0

Related Questions