'Python pocketsphinx RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly
I am trying to make a Python app that can record audio and translate it into english text using PyAudio, SpeechRecognition and PocketSphinx. I'm running on a Mac OS X El Capitan, version 10.11.2.
Following a tutorial like this one and others, I've downloaded PyAudio version 0.2.9, SpeechRecognition as well as PocketSphinx. I've installed them into a Conda environment. I have followed the instructions from this site to use brew install swig git python
on my OS X, hoping it would help.
This is my code:
# Load packages
import speech_recognition as sr
import sphinxbase
import pocketsphinx
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# write audio to a WAV file
with open("microphone-results.wav", "wb") as f:
f.write(audio.get_wav_data())
So far things are working great. I can record and play back my WAV file no problems. But here is where things go wrong...
r = sr.Recognizer()
with sr.AudioFile('microphone-results.wav') as source:
audio = r.record(source) # read the entire audio file
try:
print("You said " + r.recognize_sphinx(audio))
except LookupError: # speech is unintelligible
print("Could not understand audio")
When I run this code I get:
RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly.
I have installed PocketSphinx and Sphinxbase both globally and in virtual conda envs but to no avail. Documentation on this error on Google / SO posts is close to zero so I'm not sure what is going on. Any help/ advice would be greatly appreciated.
Here is a list of my installed packages and their versions for my conda virtual environment:
# packages in environment at /Users/nathancheever/anaconda/envs/audio_2:
#
appnope 0.1.0 py27_0
backports-abc 0.4 <pip>
backports.ssl-match-hostname 3.4.0.2 <pip>
backports_abc 0.4 py27_0
decorator 4.0.9 py27_0
freetype 2.5.5 0
ipykernel 4.3.1 py27_0
ipython 4.1.2 py27_2
ipython-genutils 0.1.0 <pip>
ipython_genutils 0.1.0 py27_0
ipywidgets 4.1.1 py27_0
jinja2 2.8 py27_0
jsonschema 2.4.0 py27_0
jupyter 1.0.0 py27_2
jupyter-client 4.2.2 <pip>
jupyter-console 4.1.1 <pip>
jupyter-core 4.1.0 <pip>
jupyter_client 4.2.2 py27_0
jupyter_console 4.1.1 py27_0
jupyter_core 4.1.0 py27_0
libpng 1.6.17 0
markupsafe 0.23 py27_0
mistune 0.7.2 py27_1
nbconvert 4.1.0 py27_0
nbformat 4.0.1 py27_0
notebook 4.1.0 py27_2
openssl 1.0.2g 0
path.py 8.1.2 py27_1
pexpect 4.0.1 py27_0
pickleshare 0.5 py27_0
pip 8.1.1 py27_1
ptyprocess 0.5 py27_0
pyaudio 0.2.9 <pip>
pygments 2.1.3 py27_0
pyqt 4.11.4 py27_1
python 2.7.11 0
pyzmq 15.2.0 py27_0
qt 4.8.7 1
qtconsole 4.2.1 py27_0
readline 6.2 2
setuptools 20.6.7 py27_0
simplegeneric 0.8.1 py27_0
singledispatch 3.4.0.3 py27_0
sip 4.16.9 py27_0
six 1.10.0 py27_0
speechrecognition 3.4.2 <pip>
sphinxbase 0.8 <pip>
sqlite 3.9.2 0
ssl_match_hostname 3.4.0.2 py27_0
terminado 0.5 py27_1
tk 8.5.18 0
tornado 4.3 py27_0
traitlets 4.2.1 py27_0
wheel 0.29.0 py27_0
zlib 1.2.8 0
Solution 1:[1]
You will need these libraries for compiling pocketsphinx:
sudo apt-get install -qq python python-dev python-pip build-essential swig libpulse-dev
After that it's simple to install pocketsphinx:
sudo pip install pocketsphinx
Solution 2:[2]
as @Nikolay Shmyrev mentioned, you can simply
pip install pocketsphinx
to solve the issue
Solution 3:[3]
I was trying to do the same thing and had trouble with
# Make sure we have up-to-date versions of pip, setuptools and wheel:
$ pip install --upgrade pip setuptools wheel
$ pip install --upgrade pocketsphinx
from the pocketsphinx docs https://pypi.python.org/pypi/pocketsphinx
The error was
error: command 'gcc' failed with exit status 1
I am working on a mac and needed to install the x-code command line tools. From the command line
xcode-select --install
then the pip install worked and
r.recognize_sphinx(audio)
works
Solution 4:[4]
Same issue
sudo apt-get install libasound2-dev
solved it.
Python 3.6 Ubuntu 18.04.4 LTS
Solution 5:[5]
I ran into this issue recently. To add an updated clarification on error: command 'swig' failed: No such file or directory
and OP original RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly.
I fixed this issue running:
# First I wanted to make sure pip/setuptools/wheel was up to date
$ pip install --upgrade pip setuptools wheel
# then installing swig
$ sudo apt-get install swig
# and finally to ensure most recent release of PocketSphinx
$ pip install --upgrade pocketsphinx
Solution 6:[6]
I also ran into similar problem. Issue is that pocketsphinx not being installed. But when I tried to install it explicitly it spit out this:
Installing collected packages: pocketsphinx
Running setup.py install for pocketsphinx ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-54lpsfk9/pocketsphinx_4a1855908d0d459d9da4cb55a9fa821d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-54lpsfk9/pocketsphinx_4a1855908d0d459d9da4cb55a9fa821d/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-hun5knqg/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.9/pocketsphinx
cwd: /tmp/pip-install-54lpsfk9/pocketsphinx_4a1855908d0d459d9da4cb55a9fa821d/
Complete output (6 lines):
running install
running build_ext
building 'sphinxbase._sphinxbase' extension
swigging deps/sphinxbase/swig/sphinxbase.i to deps/sphinxbase/swig/sphinxbase_wrap.c
swig -python -modern -threads -Ideps/sphinxbase/include -Ideps/sphinxbase/include/sphinxbase -Ideps/sphinxbase/include/android -Ideps/sphinxbase/swig -outdir sphinxbase -o deps/sphinxbase/swig/sphinxbase_wrap.c deps/sphinxbase/swig/sphinxbase.i
error: command 'swig' failed: No such file or directory
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-54lpsfk9/pocketsphinx_4a1855908d0d459d9da4cb55a9fa821d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-54lpsfk9/pocketsphinx_4a1855908d0d459d9da4cb55a9fa821d/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-hun5knqg/install-record.txt --single-version-externally-managed --compile --install-headers /usr/include/python3.9/pocketsphinx Check the logs for full command output.
Going through the error found this: error: command 'swig' failed: No such file or directory
and tracing a bit backwards found that it is used for building some package extension; what i can infer is some sphinxbase extension. Basically, installing swig solved the issue for me.
Python: 3.9
pocketsphinx: 0.1.15
speechrecognition: 3.8.1
setuptools: 57.0.0
swig: 4.0.2-2
OS: Manjaro Linux
If these matters.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | smottt |
Solution 2 | James |
Solution 3 | memebrain |
Solution 4 | juliandeprez |
Solution 5 | Josh Crouse |
Solution 6 |