2

I am trying to get pocketsphinx to work on my raspberrypi 3. I have successfully installed it on my rpi but now it wont run correctly. I am using the example code they have for the python module on github but whenever I try to run it I get this error

Traceback (most recent call last):
 File "/home/pi/VoiceTesting/SphinxTest.py", line 14, in <module>
decoder = Decoder(config)
File "/usr/local/lib/python3.4/dist-packages/pocketsphinx/pocketsphinx.py", line 228, in __init__
this = _pocketsphinx.new_Decoder(*args)
RuntimeError: new_Decoder returned -1

I have done some googling but I wasnt able to find a solution. here is a link to the example code on the pocketsphinx github. I havent edited any of it I just copied and pasted it.

sharpchain
  • 355
  • 2
  • 7
  • 15

1 Answers1

3

This is in reference to the link you have given in the question description.

I had a similar problem which was due to the fact that 'pocketsphinx' library do not have the files en-us.lm.bin and cmudict-en-us.dict by default.

It was solved by downloading the files and pasting them to correct location and giving the correct path:

P.S.: Make sure your PocketSphinx is up-to-date. You can install/update it by executing pip install pocketsphinx on terminal.

Detailed steps are given below:

STEP-1: Giving the correct path

Get the MODELDIR by:

MODELDIR= get_model_path()

STEP-2: Download the files en-us.lm.bin and cmudict-en-us.dict

Download 'en-us.lm.bin' file from: https://github.com/cmusphinx/sphinx4/tree/master/sphinx4-data/src/main/resources/edu/cmu/sphinx/models/en-us

Download 'cmudict-en-us.dict' file from: https://github.com/cmusphinx/sphinx4/blob/master/sphinx4-data/src/main/resources/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict

STEP-3: Pasting the files to correct location.

Paste the downloaded files to the directory given by: (MODELDIR + '/en-us/')

It should be something like this: C:\Users\Username\Anaconda3\Lib\site-packages\pocketsphinx\model\en-us

STEP-4: Modifying the code

The link you have given has the following code:

config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us'))
config.set_string('-lm', path.join(MODELDIR, 'en-us/en-us.lm.bin'))
config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
decoder = Decoder(config)

Make sure the directory MODELDIR + 'en-us/en-us' actually exists.

In my case, the directory was just till MODELDIR + '/en-us'.

If this is the case, modify the above code with correct directory:

config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, 'en-us'))
config.set_string('-lm', path.join(MODELDIR, 'en-us/en-us.lm.bin'))
config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
decoder = Decoder(config)

Hope this helps :)

Krishna Choudhary
  • 615
  • 1
  • 5
  • 15