python-2.7 - pocketsphinx-python 缺少声学模型定义 (mdef)

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

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

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

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

最佳答案

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

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

请注意,即使路径中的单个字母不同,例如“_”而不是“-”也会阻止计算机找到路径。你需要精确。如果不确定什么是相对路径,可以指定绝对路径。您可以从 this tutorial 了解有关路径的更多信息.

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

关于python-2.7 - pocketsphinx-python 缺少声学模型定义 (mdef),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35773734/

相关文章:

python - 测试来自串行端口的字节

python-2.7 - Pandas groupby + transform 花费数小时处理 6 亿条记录

linux - google-cloud-sdk 安装在 CentOS/usr/local/bin 中找不到正确的 Python 2.7 版本

nlp - 来自人类语音的电话号码和出生日期

android - SpeechRecognizer - 时间限制

python - 如何遍历包含列表的字典值并删除项目?

python - 使用 gzip 优化上传到驱动器使用 API v3 Python 3

python-3.x - 使用 Python3 为 Kubernetes 创建 YAML

python:替代匿名函数

c# - 使用 SAPI 将语音转换为文本