缺少使用pocketsphinx-python的声学模型定义(mdef)

时间:2016-03-03 13:37:39

标签: python-2.7 python-3.x speech-recognition pocketsphinx

我最近在Lubuntu 15.10上安装了pocketsphinx-python,我想在音频文件(最好是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()])

我是否完全偏离了我的代码,或者我还需要做些什么才能让它正常工作?

1 个答案:

答案 0 :(得分:3)

您需要一条正确的模型路径。如果你的模型在/ home / ingrid / model / en-us中,你需要写:

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

请注意,即使是路径中的单个字母差异,例如&#34; _&#34;而不是&#34; - &#34;阻止计算机查找路径。你需要准确。如果您不确定什么是相对路径,则可以指定绝对路径。您可以从this tutorial了解有关路径的详情。

hub4是旧型号,不建议使用它。对于8khz,您可以使用this model