我已经安装了 PocketSphinx(python-pocketsphinx、pocketsphinx-hmm-wsj1、pocketsphinx-lm-wsj),但是由于尝试运行一段 Python3 代码来识别音频文件中的语音而出现此错误。
$ python3 web_speech_api.py 02-29-2016_00-12_msg1.wav
Fatal Python error: Py_Initialize: Unable to get the locale encoding
File "/usr/lib/python2.7/encodings/__init__.py", line 123
raise CodecRegistryError,\
^
SyntaxError: invalid syntax
Current thread 0x00007fe1548de700 (most recent call first):
Aborted (core dumped)
我安装了 Python 2.7、Python 3.5 和 Anaconda 以使事情变得复杂,我猜这个错误可能是由于某种原因造成的?
我已将以下几行添加到我的~/.bachrc
.
export PYTHONPATH=/usr/lib/python2.7
export PATH=$PATH:$PYTHONPATH
不确定是放 python3.5 还是 2.7,但是 3.5 给了我一个错误[...] ImportError: No module named '_sysconfigdata_m'
。我还删除了为设置 anaconda 的路径而自动添加的行,并且不需要此项目的 Anaconda 包。
$ which python
/usr/bin/python
$ echo "$PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/python2.7
如果有任何帮助,这里也是代码:
#!/usr/bin/ python
import sys
import pocketsphinx
if __name__ == "__main__":
hmdir = "/usr/share/pocketsphinx/model/hmm/wsj1"
lmdir = "/usr/share/pocketsphinx/model/lm/wsj/wlist5o.3e-7.vp.tg.lm.DMP"
dictd = "/usr/share/pocketsphinx/model/lm/wsj/wlist5o.dic"
wavfile = sys.argv[1]
speechRec = pocketsphinx.Decoder(hmm = hmdir, lm = lmdir, dict = dictd)
wavFile = file(wavfile,'rb')
speechRec.decode_raw(wavFile)
result = speechRec.get_hyp()
print(result)
我非常感谢帮助纠正我的错误,并希望也能整理出我的不同 Python 版本的混乱......