Skip to content
Advertisement

why is my speech recognition not working in python

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

Advertisement

Answer

brew install portaudio pip install pyaudio

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement