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
JavaScript
x
97
97
1
Defaulting to user installation because normal site-packages is not writeable
2
Collecting pyaudio
3
Using cached PyAudio-0.2.11.tar.gz (37 kB)
4
Preparing metadata (setup.py) done
5
Building wheels for collected packages: pyaudio
6
Building wheel for pyaudio (setup.py) error
7
error: subprocess-exited-with-error
8
9
× python setup.py bdist_wheel did not run successfully.
10
│ exit code: 1
11
╰─> [16 lines of output]
12
running bdist_wheel
13
running build
14
running build_py
15
creating build
16
creating build/lib.macosx-10.9-universal2-3.10
17
copying src/pyaudio.py -> build/lib.macosx-10.9-universal2-3.10
18
running build_ext
19
building '_portaudio' extension
20
creating build/temp.macosx-10.9-universal2-3.10
21
creating build/temp.macosx-10.9-universal2-3.10/src
22
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
23
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
24
#include "portaudio.h"
25
^~~~~~~~~~~~~
26
1 error generated.
27
error: command '/usr/bin/clang' failed with exit code 1
28
[end of output]
29
30
note: This error originates from a subprocess, and is likely not a problem with pip.
31
ERROR: Failed building wheel for pyaudio
32
Running setup.py clean for pyaudio
33
Failed to build pyaudio
34
Installing collected packages: pyaudio
35
Running setup.py install for pyaudio error
36
error: subprocess-exited-with-error
37
38
× Running setup.py install for pyaudio did not run successfully.
39
│ exit code: 1
40
╰─> [16 lines of output]
41
running install
42
running build
43
running build_py
44
creating build
45
creating build/lib.macosx-10.9-universal2-3.10
46
copying src/pyaudio.py -> build/lib.macosx-10.9-universal2-3.10
47
running build_ext
48
building '_portaudio' extension
49
creating build/temp.macosx-10.9-universal2-3.10
50
creating build/temp.macosx-10.9-universal2-3.10/src
51
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
52
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
53
#include "portaudio.h"
54
^~~~~~~~~~~~~
55
1 error generated.
56
error: command '/usr/bin/clang' failed with exit code 1
57
[end of output]
58
59
note: This error originates from a subprocess, and is likely not a problem with pip.
60
error: legacy-install-failure
61
62
× Encountered error while trying to install package.
63
╰─> pyaudio
64
65
note: This is an issue with the package mentioned above, not pip.
66
hint: See above for output from the failure. ```
67
68
69
import speech_recognition as sr
70
import pyttsx3
71
72
listener = sr.Recognizer()
73
engine = pyttsx3.init()
74
75
voices = engine.getProperty('voices')
76
engine.setProperty('voice', voices[0].id)
77
78
def talk(text):
79
engine.say(text)
80
engine.runAndWait()
81
82
talk("i am your alexa, what can i do for you")
83
84
try:
85
with sr.microphone() as source:
86
print('listening...')
87
voice = listener.listen(source)
88
command = listener.recognize_google(voice)
89
command = command.lower()
90
if 'alexa' in command:
91
engine.say(command)
92
engine.runAndWait()
93
print(command)
94
except:
95
pass
96
97
Advertisement
Answer
brew install portaudio pip install pyaudio