3

我最近安装pocketsphinx-python在 Lubuntu 15.10 上,我想对音频文件(最好是 8kH)进行语音识别。尽管我不明白,但我收到一条错误消息,因为我的文件mdef夹中有一个名为的文件/usr/share/pocketsphinx/model/hmm/en_US/,它说我没有:

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

这是我的 Python3 脚本:

#!/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()])

我是否完全偏离了我的代码的轨道,还是我必须做其他事情才能让它工作?

4

1 回答 1

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.

于 2016-03-03T16:49:32.723 回答