Search code examples
pythonpython-3.xspeech-recognitionpyaudio

Could not find pyaudio check installation in mac


I have installed portaudio using brew and installed speechRecognition, pyaudio using pip3 in my macos. I am getting error while running following code

CODE:

    #!/usr/bin/env python
    # Python 3
    import os
    import sys
    import speech_recognition as sr
    r = sr.Recognizer()

    with sr.Microphone() as source:
        print ("say something!");
        audio = r.listen(source)

     try:
          print("google thinks you said" +r.recognize_google(audio))

     except:
          pass

ERROR:

     Traceback (most recent call last):
     File "test.py", line 8, in <module>
     with sr.Microphone() as source:
     File "/Library/Python/2.7/site-
     packages/speech_recognition/__init__.py", line 79, in __init__
      self.pyaudio_module = self.get_pyaudio()
     File "/Library/Python/2.7/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 am using python-shell for running this python script in my nodejs application. when I run only this script with the python3 test.py, it's working but with python test.py, it is not working. in my node application also it is not working. I think node is executing this script on basic python version 2.7. I am using MacOs sierra operating system.

Please help me thanks in advance:-)


Solution

  • It seems you've installed packages for python3 and that's the reason it is working with it but while running script from python2.7 it is giving out error, to resolve it you have to install same packages for python2.7 version.

    Can you run command following command and check if it works.

    pip2.7 install pyaudio