0

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...

Ingrid
  • 516
  • 6
  • 18
  • 1
    You are using very outdated pocketsphinx. Correct one is here http://github.com/cmusphinx/pocketsphinx-python – Nikolay Shmyrev Mar 02 '16 at 19:28
  • 1
    Btw, you need to uninstall old pocketsphinx before you install a new one – Nikolay Shmyrev Mar 02 '16 at 19:28
  • Oh, thanks! The current pocketsphinx-python seemed to work fine to install. I just ran the commands in the Readme at the link you sent and it seems to work for both Python2 and 3! – Ingrid Mar 03 '16 at 06:15
  • Possible duplicate of [Python pocketsphinx RequestError: missing PocketSphinx module: ensure that PocketSphinx is set up correctly](https://stackoverflow.com/questions/36523705/python-pocketsphinx-requesterror-missing-pocketsphinx-module-ensure-that-pocke) – Nikolay Shmyrev Jul 16 '17 at 09:08

0 Answers0