why is my speech recognition not working in python - 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

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.

brew install portaudio
pip install pyaudio

Related

error when I am trying to install pyaudio on Mac OS Ventura

I know this questions was asked couple of times, but all the answers do not work for me.
I get this error when I try to install PyAudio:
Building wheels for collected packages: pyaudio
WARNING: Ignoring --global-option when building pyaudio using PEP 517
Building wheel for pyaudio (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for pyaudio (pyproject.toml) 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-x86_64-cpython-39
copying src/pyaudio.py -> build/lib.macosx-10.9-x86_64-cpython-39
running build_ext
building '_portaudio' extension
creating build/temp.macosx-10.9-x86_64-cpython-39
creating build/temp.macosx-10.9-x86_64-cpython-39/src
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DMACOSX=1 -I/usr/local/include -I/usr/include -I/Users/myname/PycharmProjects/a/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-x86_64-cpython-39/src/_portaudiomodule.o
src/_portaudiomodule.c:31:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
^~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/gcc' 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
Failed to build pyaudio
ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects
From what I can tell, it's ignoring the global portaudio and looking for another one ?
I removed and installed already portaudio with brew, I update everything, I installed command line for Xcode, I tried with anaconda in notebook, same error there as well. I already tried to installed wheel and said its fulfilled.
Where to put this portaudio file so it see it ?
Any suggestions to fix this error ?
Thanks

How to install pyAudio without subprocess-exited-with-error code, "failed to build wheels"

Every time I run pip install pyaudio I get the following error
pip3 install pyaudio
Collecting pyaudio
Using cached PyAudio-0.2.12.tar.gz (42 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyaudio
Building wheel for pyaudio (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for pyaudio (pyproject.toml) 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-cpython-310
copying src/pyaudio.py -> build/lib.macosx-10.9-universal2-cpython-310
running build_ext
building '_portaudio' extension
creating build/temp.macosx-10.9-universal2-cpython-310
creating build/temp.macosx-10.9-universal2-cpython-310/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/usr/local/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-universal2-cpython-310/src/_portaudiomodule.o
src/_portaudiomodule.c:31: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
Failed to build pyaudio
ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects
I tried pip install, reinstalling port audio, but nothing works, any advice how to tackle this problem?
This was tested on an M1 Max, so pyaudio should definitely support the platform.
Since you have portaudio installed from homebrew, do this...
LDFLAGS="-L$(brew --prefix portaudio)/lib" CFLAGS="-I$(brew --prefix portaudio)/include" pip install pyaudio
And hopefully you have it built and installed:
python3 -c "import pyaudio; print(pyaudio.__version__)"
0.2.12
I am a M1 mac user.
There has been overwhelming answers toward this way which hasn't worked for me.
when installing pyaudio, pip cannot find portaudio.h in /usr/local/include
But I found #wkl's answer worked for me ! thanks.
Yesterday I started a project with a voice assistant, but stumbled on PyAudio :((
I tried a lot of different things, as QUANTUM says, but when I tried what WKL recommends, everything fell into place! Amazing, thank you WKL 🥳🍾 You saved my nerve cells!
INSTEAD OF THIS: python3 -c "import pyaudio; print(pyaudio.__version__)"
BETTER USE THIS: pip show pyaudio
⚠️ I'm sorry to post here as I'm a new user and can't rate his work for the rating to take effect.

Can't find `lz4` header when installing `roslz4` with pip on a Mac

I'm trying to install roslz4 on my Mac, and I get the following error.
In file included from ros_comm/utilities/roslz4/src/_roslz4module.c:37:
include/roslz4/lz4s.h:38:10: fatal error: 'lz4.h' file not found
#include <lz4.h>
^~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
[end of output]
To counter this, I installed lz4 with brew which ran successfully
> brew install lz4
==> Downloading https://ghcr.io/v2/homebrew/core/lz4/manifests/1.9.3
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/lz4/blobs/sha256:d222923849a6fefd391ab6705f1468c10d287c08ab9c4b5053a18a552139e262
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:d222923849a6fefd391ab6705f1468c10d287c08ab9c4b5053a18a552139e262?se=2022-06-14T22%3A20%3A00Z&s
######################################################################## 100.0%
==> Pouring lz4--1.9.3.arm64_monterey.bottle.tar.gz
🍺 /opt/homebrew/Cellar/lz4/1.9.3: 22 files, 620.6KB
==> Running `brew cleanup lz4`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
However, it does not appear to have resolved the problem.
Full pip output:
> pip install --extra-index-url https://rospypi.github.io/simple/ roslz4
Looking in indexes: https://pypi.org/simple, https://rospypi.github.io/simple/
Collecting roslz4
Using cached https://github.com/rospypi/simple/raw/any/roslz4/roslz4-1.14.3.post2.tar.gz (18 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: roslz4
Building wheel for roslz4 (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [21 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.14-arm64-3.8
creating build/lib.macosx-10.14-arm64-3.8/roslz4
copying ros_comm/utilities/roslz4/src/roslz4/__init__.py -> build/lib.macosx-10.14-arm64-3.8/roslz4
running build_ext
building '_roslz4' extension
creating build/temp.macosx-10.14-arm64-3.8
creating build/temp.macosx-10.14-arm64-3.8/ros_comm
creating build/temp.macosx-10.14-arm64-3.8/ros_comm/utilities
creating build/temp.macosx-10.14-arm64-3.8/ros_comm/utilities/roslz4
creating build/temp.macosx-10.14-arm64-3.8/ros_comm/utilities/roslz4/src
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -DXXH_NAMESPACE=ROSLZ4_ -Iinclude -Iroscpp_core/cpp_common/include -I/Users/cmauceri/Workspace/run-mgmt/jupyter_venv/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c ros_comm/utilities/roslz4/src/_roslz4module.c -o build/temp.macosx-10.14-arm64-3.8/ros_comm/utilities/roslz4/src/_roslz4module.o -Wno-strict-prototypes -Wno-missing-field-initializers -Wno-unused-variable -Wno-strict-aliasing
In file included from ros_comm/utilities/roslz4/src/_roslz4module.c:37:
include/roslz4/lz4s.h:38:10: fatal error: 'lz4.h' file not found
#include <lz4.h>
^~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for roslz4
Running setup.py clean for roslz4
Failed to build roslz4
Installing collected packages: roslz4
Running setup.py install for roslz4 ... error
error: subprocess-exited-with-error
× Running setup.py install for roslz4 did not run successfully.
│ exit code: 1
╰─> [21 lines of output]
running install
running build
running build_py
creating build
creating build/lib.macosx-10.14-arm64-3.8
creating build/lib.macosx-10.14-arm64-3.8/roslz4
copying ros_comm/utilities/roslz4/src/roslz4/__init__.py -> build/lib.macosx-10.14-arm64-3.8/roslz4
running build_ext
building '_roslz4' extension
creating build/temp.macosx-10.14-arm64-3.8
creating build/temp.macosx-10.14-arm64-3.8/ros_comm
creating build/temp.macosx-10.14-arm64-3.8/ros_comm/utilities
creating build/temp.macosx-10.14-arm64-3.8/ros_comm/utilities/roslz4
creating build/temp.macosx-10.14-arm64-3.8/ros_comm/utilities/roslz4/src
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -DXXH_NAMESPACE=ROSLZ4_ -Iinclude -Iroscpp_core/cpp_common/include -I/Users/cmauceri/Workspace/run-mgmt/jupyter_venv/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c ros_comm/utilities/roslz4/src/_roslz4module.c -o build/temp.macosx-10.14-arm64-3.8/ros_comm/utilities/roslz4/src/_roslz4module.o -Wno-strict-prototypes -Wno-missing-field-initializers -Wno-unused-variable -Wno-strict-aliasing
In file included from ros_comm/utilities/roslz4/src/_roslz4module.c:37:
include/roslz4/lz4s.h:38:10: fatal error: 'lz4.h' file not found
#include <lz4.h>
^~~~~~~
1 error generated.
error: command 'clang' failed with exit status 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.
╰─> roslz4
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
Do I need to add the location of lz4 headers to an environment variable? How can I get pip to find the header?
After doing brew install lz4 the following (from this SO post by rgov) worked for me without the need of any source code changes:
CFLAGS="-I$(brew --prefix lz4)/include" \
LDFLAGS="-L$(brew --prefix lz4)/lib" \
pip install roslz4 --extra-index-url https://rospypi.github.io/simple/
Answer from a coworker:
My solution was to download the roslz4 tarball and manually add the include folders and library symbols into the setup config, then run python setup.py install
Here are the first few lines of my setup.py file (which includes my addition to include and lib)
import platform
from setuptools import setup, Extension
extra_compile_args = []
include_dirs = [
"include",
"roscpp_core/cpp_common/include",
"/usr/local/Cellar/lz4/1.9.3/include",
]
libraries = ["lz4"]
library_dirs = ["/usr/local/Cellar/lz4/1.9.3/lib"]
define_macros = [
("XXH_NAMESPACE", "ROSLZ4_"),
]
My changes are the lines with "Cellar" and "library_dirs"

pyaudio - legacy-install-failure

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.
Hey this question was already asked : PyAudio error at the time of intallation (subprocess-exited-with-error)
You need to download the wheel (.whl) file on the website quoted in the answer (https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio).
And then, you install it using pip install filename.whl using the cmd in the directory where you downloaded the file in .whl .

How can I solve openexr install error in Ubuntu?

I'm try to install openexr in ubuntu with pip install openexr. But it's not work. Also I tried to install with .whl file, but error is returned.
ERROR: OpenEXR-1.3.7-cp39-cp39-win_amd64.whl is not a supported wheel on this platform.
How can I solve this problem?
Python : 3.9.5
Ubuntu : 21.04
pip : 22.0.4
Error log:
Collecting openexr
Using cached OpenEXR-1.3.7.tar.gz (11 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: openexr
Building wheel for openexr (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [13 lines of output]
Looking for libOpenEXR...
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.9
copying Imath.py -> build/lib.linux-x86_64-3.9
running build_ext
building 'OpenEXR' extension
creating build/temp.linux-x86_64-3.9
clang-9 -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/build/python3.9-FZ7wim/python3.9-3.9.5=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/usr/include/OpenEXR -I/usr/local/include/OpenEXR -I/opt/local/include/OpenEXR -I/usr/include/Imath -I/usr/local/include/Imath -I/opt/local/include/Imath -I/home/donghyuk/repo/2022_pm_research/PC-Differentiable/venv/include -I/usr/include/python3.9 -c OpenEXR.cpp -o build/temp.linux-x86_64-3.9/OpenEXR.o -g -DVERSION=\"1.3.7\"
clang: error: unknown argument: '-ffile-prefix-map=/build/python3.9-FZ7wim/python3.9-3.9.5=.'
error: command '/usr/bin/clang-9' 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 openexr
Running setup.py clean for openexr
Failed to build openexr
Installing collected packages: openexr
Running setup.py install for openexr ... error
error: subprocess-exited-with-error
× Running setup.py install for openexr did not run successfully.
│ exit code: 1
╰─> [15 lines of output]
Looking for libOpenEXR...
running install
/home/donghyuk/repo/2022_pm_research/PC-Differentiable/venv/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.9
copying Imath.py -> build/lib.linux-x86_64-3.9
running build_ext
building 'OpenEXR' extension
creating build/temp.linux-x86_64-3.9
clang-9 -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/build/python3.9-FZ7wim/python3.9-3.9.5=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/usr/include/OpenEXR -I/usr/local/include/OpenEXR -I/opt/local/include/OpenEXR -I/usr/include/Imath -I/usr/local/include/Imath -I/opt/local/include/Imath -I/home/donghyuk/repo/2022_pm_research/PC-Differentiable/venv/include -I/usr/include/python3.9 -c OpenEXR.cpp -o build/temp.linux-x86_64-3.9/OpenEXR.o -g -DVERSION=\"1.3.7\"
clang: error: unknown argument: '-ffile-prefix-map=/build/python3.9-FZ7wim/python3.9-3.9.5=.'
error: command '/usr/bin/clang-9' 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.
╰─> openexr
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
The option ffile-prefix-map which is used in the compilation here is only available in clang starting with version 10, see here. You seem to have clang-9, so simply get a newer version:
sudo apt install clang-11
Additional Note: Your whl is for windows, as marked by the tag win_amd64 whcih is why it won't install to your ubuntu system

Categories

Resources