Reputation: 526
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?
Upvotes: 3
Views: 2777
Reputation: 25220
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.
Upvotes: 3