我安装了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版本......