-1

I am working on this project and its simply a desktop Assistant I am using speech recognition and pyttsx3 but the speech recognition is not working after the try nothing is executing it just jumps to except and passes can someone tell me why? and how I can fix it edit: I tried to install pyaudio but it won't let me I keep getting errors

Defaulting to user installation because normal site-packages is not writeable
Collecting pyaudio
  Using cached 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
  ╰─> [16 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-3.10
      copying src/pyaudio.py -> build/lib.macosx-10.9-universal2-3.10
      running build_ext
      building '_portaudio' extension
      creating build/temp.macosx-10.9-universal2-3.10
      creating build/temp.macosx-10.9-universal2-3.10/src
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DMACOSX=1 -I/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-universal2-3.10/src/_portaudiomodule.o
      src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
      #include "portaudio.h"
               ^~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [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
  ╰─> [16 lines of output]
      running install
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-3.10
      copying src/pyaudio.py -> build/lib.macosx-10.9-universal2-3.10
      running build_ext
      building '_portaudio' extension
      creating build/temp.macosx-10.9-universal2-3.10
      creating build/temp.macosx-10.9-universal2-3.10/src
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DMACOSX=1 -I/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-universal2-3.10/src/_portaudiomodule.o
      src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
      #include "portaudio.h"
               ^~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [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. ```


    import speech_recognition as sr
import pyttsx3

listener = sr.Recognizer()
engine = pyttsx3.init()

voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id) 

def talk(text):
     engine.say(text)
     engine.runAndWait()

talk("i am your alexa, what can i do for you")

try:
    with sr.microphone() as source:
        print('listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        command = command.lower()
        if 'alexa' in command:
            engine.say(command)
            engine.runAndWait()
            print(command)
except:
    pass

  • If you didn't use an empty `except` block, python would tell you exactly what the problem is. Have you tried running your code without the `try:`? – G. Anderson Mar 22 '22 at 17:44
  • see [What is wrong with using a bare 'except'?](https://stackoverflow.com/questions/54948548/what-is-wrong-with-using-a-bare-except) – G. Anderson Mar 22 '22 at 17:45
  • @G.Anderson I did and I got a ton of errors "Traceback (most recent call last): File "/Users/rawanarafat/Desktop/alexa/venv/lib/python3.9/site-packages/speech_recognition/__init__.py", line 108, in get_pyaudio import pyaudio ModuleNotFoundError: No module named 'pyaudio' " – rawan arafat Mar 22 '22 at 17:50
  • Then that's a good place to start. Searching for that error give several results on how to fix it (like [This question and answer](https://stackoverflow.com/questions/55340826/speech-recognition-cant-import-pyaudio-modulenotfounderror), then if you get another error, fix that one, etc. That's why suppressing/hiding your errors is counterproductive – G. Anderson Mar 22 '22 at 17:55
  • 2
    "No Module named 'pyaudio'" seems like a pretty hot clue. – JNevill Mar 22 '22 at 17:55
  • @G.Anderson I tried to install pyaudio but it won't let me I keep getting errors – rawan arafat Mar 22 '22 at 17:58
  • 2
    And what did you find when you searched online for those errors? Did you open a new question with a [mcve] including the full traceback of the error so that we can understand how to help? – G. Anderson Mar 22 '22 at 18:00
  • they showed how to install it but I tried everything and nothing is working and I tried to open a new question but it keeps saying overreached my limit – rawan arafat Mar 22 '22 at 18:04
  • @G.Anderson I added the error in the question – rawan arafat Mar 22 '22 at 18:18
  • 1
    So when I search for that error, I find [pyaudio installation always fails on mac](https://stackoverflow.com/questions/62751582/pyaudio-installation-always-fails-on-mac) What have you tied, and what went wrong when you attempted to solve the problem yourself? – G. Anderson Mar 22 '22 at 19:19
  • @G.Anderson I tried updating Xcode then updated pip and did pip3 install pyaudio and still didn't work I am still getting the same error – rawan arafat Mar 22 '22 at 19:45

2 Answers2

0

PyAudio requires PortAudio be installed on your system. Check out the Installation section of the PyAudio documentation.

For Mac OS, the following should do the trick:

brew install portaudio
pip install pyaudio

There are probably other acceptable ways to install PortAudio too if you're not already using Homebrew.

dstricks
  • 1,465
  • 12
  • 23
0

brew install portaudio pip install pyaudio

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 21 '22 at 05:52