解决错误:’pocketsphinx/model/en-us/en-us’ does not contain acoustic model definition ‘mdef’

python pocketsphinx 实例代码

在使用pocketsphinx python的时候,按照Github上面的提示,运行测试脚本:

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

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/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)

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

解决错误:’pocketsphinx/model/en-us/en-us’ does not contain acoustic model definition ‘mdef’

实例代码代码报错:’pocketsphinx/model/en-us/en-us’ does not contain acoustic model definition ‘mdef’

原因是因为实例代码中给定的model和data路径与你实际安装pocketsphinx不符合。例如你在/home/yourname/tools/pocketsphinx/下安装的,那么你需要将脚本中的MODELDIR和DATADIR做对应的修改,可以使用绝对路径或者相对路径。例如:

/home/yourname/tools/pocketsphinx/pocketsphinx-python/pocketsphinx/model
/home/yourname/tools/pocketsphinx/pocketsphinx-python/pocketsphinx/test/data

如果你是使用pip安装,那么路径对应python packages的路径:
/usr/local/lib/python3.5/dist-packages/pocketsphinx/model

发表评论

电子邮件地址不会被公开。 必填项已用*标注

8 + 1 =