首页 > 解决方案 > RuntimeError:new_Decoder 使用 pocketsphinx 返回 -1

问题描述

我正在尝试使用这个库来处理语音识别。我只是使用他们在此处提供的基本使用脚本。

这是脚本:

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

这是错误:

RuntimeError                              Traceback (most recent call last)
<ipython-input-14-fdecd3fd35b8> in <module>()
      4 config.set_string('-lm', path.join(MODELDIR, 'en-us/en-us.lm.bin'))
      5 config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
----> 6 decoder = Decoder(config)

C:\Programmes\lib\site-packages\pocketsphinx\pocketsphinx.py in __init__(self, *args)
    270         __init__(Decoder self, Config config) -> Decoder
    271         """
--> 272         this = _pocketsphinx.new_Decoder(*args)
    273         try:
    274             self.this.append(this)

RuntimeError: new_Decoder returned -1

如果一切都安装良好,我检查得很好,并且我在互联网上获得了音频进行测试。

标签: pythonspeech-to-textpocketsphinx

解决方案


推荐阅读