Python pocketsphinx RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly
Python pocketsphinx RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly
我正在尝试制作一个 Python 应用程序,它可以使用 PyAudio、SpeechRecognition 和 PocketSphinx 录制音频并将其翻译成英文文本。我 运行正在使用 Mac OS X El Capitan,版本 10.11.2。
按照 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 这样的教程在我的 OS X 上使用 brew install swig git python
,希望它能有所帮助。
这是我的代码:
# 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())
到目前为止一切都很好。我可以毫无问题地录制和播放我的 WAV 文件。但是这里出了问题...
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")
当我 运行 这段代码时,我得到:
RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly.
我已经在全局和虚拟 conda envs 中安装了 PocketSphinx 和 Sphinxbase,但无济于事。 Google / SO 帖子上关于此错误的文档接近于零,因此我不确定发生了什么。任何帮助/建议将不胜感激。
这里是我安装的软件包列表及其适用于我的 conda 虚拟环境的版本:
# 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
如@Nikolay Shmyrev 所述,您可以简单地
pip install pocketsphinx
解决问题
您将需要这些库来编译 pocketsphinx:
sudo apt-get install -qq python python-dev python-pip build-essential swig libpulse-dev
之后安装 pocketsphinx 就很简单了:
sudo pip install pocketsphinx
我试图做同样的事情但遇到了问题
# Make sure we have up-to-date versions of pip, setuptools and wheel:
$ pip install --upgrade pip setuptools wheel
$ pip install --upgrade pocketsphinx
来自 pocketsphinx 文档 https://pypi.python.org/pypi/pocketsphinx
错误是
error: command 'gcc' failed with exit status 1
我正在开发 mac 并且需要安装 x-code 命令行工具。
从命令行
xcode-select --install
然后 pip 安装成功,
r.recognize_sphinx(audio)
有效
同样的问题
sudo apt-get install libasound2-dev
解决了。
Python 3.6
Ubuntu 18.04.4 LTS
我也运行遇到了类似的问题。问题是没有安装 pocketsphinx。但是当我试图显式安装它时,它吐出了这个:
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.
通过错误发现:error: command 'swig' failed: No such file or directory
并向后追踪一点发现它用于构建一些包扩展;我可以推断的是一些 sphinxbase 扩展。基本上,安装 swig 解决了我的问题。
Python: 3.9
口袋狮身人面像:0.1.15
语音识别:3.8.1
安装工具:57.0.0
痛饮:4.0.2-2
OS: 曼扎罗 Linux
如果这些很重要。
我最近 运行 关注这个问题。添加对 error: command 'swig' failed: No such file or directory
和 OP 原始 RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly.
的更新说明
我解决了这个问题 运行:
# 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
我正在尝试制作一个 Python 应用程序,它可以使用 PyAudio、SpeechRecognition 和 PocketSphinx 录制音频并将其翻译成英文文本。我 运行正在使用 Mac OS X El Capitan,版本 10.11.2。
按照 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 这样的教程在我的 OS X 上使用 brew install swig git python
,希望它能有所帮助。
这是我的代码:
# 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())
到目前为止一切都很好。我可以毫无问题地录制和播放我的 WAV 文件。但是这里出了问题...
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")
当我 运行 这段代码时,我得到:
RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly.
我已经在全局和虚拟 conda envs 中安装了 PocketSphinx 和 Sphinxbase,但无济于事。 Google / SO 帖子上关于此错误的文档接近于零,因此我不确定发生了什么。任何帮助/建议将不胜感激。
这里是我安装的软件包列表及其适用于我的 conda 虚拟环境的版本:
# 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
如@Nikolay Shmyrev 所述,您可以简单地
pip install pocketsphinx
解决问题
您将需要这些库来编译 pocketsphinx:
sudo apt-get install -qq python python-dev python-pip build-essential swig libpulse-dev
之后安装 pocketsphinx 就很简单了:
sudo pip install pocketsphinx
我试图做同样的事情但遇到了问题
# Make sure we have up-to-date versions of pip, setuptools and wheel:
$ pip install --upgrade pip setuptools wheel
$ pip install --upgrade pocketsphinx
来自 pocketsphinx 文档 https://pypi.python.org/pypi/pocketsphinx
错误是
error: command 'gcc' failed with exit status 1
我正在开发 mac 并且需要安装 x-code 命令行工具。 从命令行
xcode-select --install
然后 pip 安装成功,
r.recognize_sphinx(audio)
有效
同样的问题
sudo apt-get install libasound2-dev
解决了。
Python 3.6 Ubuntu 18.04.4 LTS
我也运行遇到了类似的问题。问题是没有安装 pocketsphinx。但是当我试图显式安装它时,它吐出了这个:
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.
通过错误发现:error: command 'swig' failed: No such file or directory
并向后追踪一点发现它用于构建一些包扩展;我可以推断的是一些 sphinxbase 扩展。基本上,安装 swig 解决了我的问题。
Python: 3.9
口袋狮身人面像:0.1.15
语音识别:3.8.1
安装工具:57.0.0
痛饮:4.0.2-2
OS: 曼扎罗 Linux
如果这些很重要。
我最近 运行 关注这个问题。添加对 error: command 'swig' failed: No such file or directory
和 OP 原始 RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly.
我解决了这个问题 运行:
# 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