【发布时间】:2017-11-11 22:15:34
【问题描述】:
我有问题。当我通过控制台打开 pocketsphinx 时,一切正常:
pi@raspberrypi:~ $ pocketsphinx_continuous -hmm /usr/local/share/pocketsphinx/model/en-us/en-us -lm 6764.lm -dict 6764.dic -samprate 16000 -inmic yes -adcdev plughw:0,0
但是,当我尝试通过 python 脚本运行它时,pocketsphinx 识别出错误的单词。
这是python脚本的代码:
import sys, os, pyaudio
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
modeldir = "/home/pi/Downloads/sphinx4-5prealpha-src/sphinx4-data/src/main/resources/edu/cmu/sphinx/models/"
# Create a decoder with certain model
config = Decoder.default_config()
config.set_string('-hmm', os.path.join(modeldir, 'en-us/en-us'))
config.set_string('-dict', '/home/pi/Downloads/6764.dic')
config.set_string('-lm', '/home/pi/Downloads/6764.lm')
config.set_string('-samprate', '16000')
config.set_string('-adcdev', 'plughw:0,0')
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True)
stream.start_stream()
decoder = Decoder(config)
decoder.start_utt()
print ("RECOGNITION STARTED")
while True:
buf = stream.read(1024)
decoder.process_raw(buf, False, False)
if decoder.hyp() != None:
print ([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()])
print ("Detected keyword, restarting search")
decoder.end_utt()
decoder.start_utt()
我不知道怎么了。
【问题讨论】:
-
您在连续示例中使用了错误的代码。正确的代码在这里:github.com/cmusphinx/pocketsphinx/blob/master/swig/python/test/…
标签: speech-recognition pocketsphinx