3

I have recently installed pocketsphinx-python on Lubuntu 15.10 and am wanting to do speech recognition on an audio file (preferably of 8kH). I am getting an error message though that I don't understand, because I have a file called mdef in my folder /usr/share/pocketsphinx/model/hmm/en_US/, which it says I don't:

INFO: feat.c(715): Initializing feature stream to type: '1s_c_d_dd', ceplen=13, CMN='current', VARNORM='no', AGC='none'
INFO: cmn.c(143): mean[0]= 12.00, mean[1..12]= 0.0
ERROR: "acmod.c", line 83: Folder 'pocketsphinx/model/en_us/hub4wsj_sc_8k/' does not contain acoustic model definition 'mdef'
Traceback (most recent call last):
  File "web_speech_api.py", line 16, in <module>
    decoder = Decoder(config)
  File "/home/ingrid/.local/lib/python3.4/site-packages/pocketsphinx/pocketsphinx.py", line 271, in __init__
    this = _pocketsphinx.new_Decoder(*args)
RuntimeError: new_Decoder returned -1

This is my Python3 script:

#!/usr/bin/env python
from os import environ, path

import sys
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *

MODELDIR = "pocketsphinx/model"
DATADIR = "pocketsphinx/test/data"

# Create a decoder with certain model
config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, 'en_us/hub4wsj_sc_8k/'))
config.set_string('-lm', path.join(MODELDIR, 'en_us/hub4.5000.DMP'))
config.set_string('-dict', path.join(MODELDIR, 'en_us/cmu07a.dic'))
decoder = Decoder(config)

# Decode streaming data.
decoder = Decoder(config)
decoder.start_utt()
stream = open(path.join(DATADIR, 'goforward.raw'), 'rb')
while True:
   buf = stream.read(1024)
   if buf:
      decoder.process_raw(buf, False, False)
   else:
      break
decoder.end_utt()
print ('Best hypothesis segments: ', [seg.word for seg in decoder.seg()])

Am I completely off track with my code or is there something else I've got to do to get it working?

Ingrid
  • 516
  • 6
  • 18

1 Answers1

3

You need to a correct path to the model. If you model is in /home/ingrid/model/en-us, you need to write:

 config.set_string('-hmm', "/home/ingrid/model/en-us")

Please note that even single letter difference in the path, for example, "_" instead of "-" prevents computer from finding the path. You need to be precise. If you are not sure what is relative path, you can specify an absolute path. You can learn more about paths from this tutorial.

hub4 is an old model, it is NOT recommended to use it. For 8khz you can use this model.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • Thanks! I was joining my path up (path.join(X,Y)), which obviously confused me. Thanks also for the model! I now got a bit further with my recognition. Not getting actual words as output yet though, only ` [SPEECH]` etc, so I guess I still have something missing... – Ingrid Mar 05 '16 at 06:41
  • 1
    Most likely your input format is wrong. It must be little endian 16bit 8khz PCM. – Nikolay Shmyrev Mar 05 '16 at 16:42
  • I changed to 8kHz and have a wav file of 16 bit, so I guess that means it's also little endian and PCM. But still not working. Is there anywhere I can ask basic questions on pocketsphinx? The wiki and tutorial don't seem to include the kind of basics I need and I can't access the forum. Does the chat work? (can't get it to) – Ingrid Mar 11 '16 at 11:36
  • 1
    Both chat and forum work for you, you can find details here http://cmusphinx.sourceforge.net/wiki/communicate To get help you need to provide more details on the problem you see - audio file, code you run and so on. – Nikolay Shmyrev Mar 11 '16 at 11:44