I have installed PocketSphinx (python-pocketsphinx, pocketsphinx-hmm-wsj1, pocketsphinx-lm-wsj), but get this error from trying to run a piece of Python3 code to recognise speech in an audio file.
$ 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)
I have both Python 2.7, Python 3.5 and Anaconda installed to make things complicated and I guess the error might be due to this somehow?
I have added the lines below to my ~/.bachrc
.
export PYTHONPATH=/usr/lib/python2.7
export PATH=$PATH:$PYTHONPATH
Wasn't sure whether to put python3.5 or 2.7, but 3.5 gave me an error [...] ImportError: No module named '_sysconfigdata_m'
.
I have also removed the line that was automatically added for setting the path to anaconda, and don't need the Anaconda packages for this project.
$ 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
Here is the code as well if it is of any help:
#!/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)
I'm very thankful for help straightening out my error and hopefully also sorting out my mess of different Python versions...