我从网站复制代码听特定字词使用Python pocketsphinx.It虽然运行,但从来没有输出关键字作为expected.This是我的代码:Pocketsphinx在python回报关键字搜索随机单词
import sys, os
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
import pyaudio
# modeldir = "../../../model"
# datadir = "../../../test/data"
modeldir="C://Users//hp//AppData//Local//Programs//Python//Python35//Lib//site-packages//pocketsphinx//model//en-us"
dictdir="C://Users//hp//AppData//Local//Programs//Python//Python35//Lib//site-packages//pocketsphinx//model//cmudict-en-us.dict"
lmdir="C://Users//hp//AppData//Local//Programs//Python//Python35//Lib//site-packages//pocketsphinx//model//en-us.lm.bin"
# Create a decoder with certain model
config = Decoder.default_config()
config.set_string('-hmm', modeldir)
config.set_string('-lm', lmdir)
config.set_string('-dict', dictdir)
config.set_string('-keyphrase', 'forward')
config.set_float('-kws_threshold', 1e+20)
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
stream.start_stream()
# Process audio chunk by chunk. On keyword detected perform action and restart search
decoder = Decoder(config)
decoder.start_utt()
while True:
buf = stream.read(1024)
if buf:
decoder.process_raw(buf, False, False)
else:
break
if decoder.hyp() != None:
#print(decoder.hyp().hypstr)
if decoder.hyp().hypstr == 'forward':
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()
此外,当我使用print(decoder.hyp().hypstr)
它只是输出随机单词时,我如果我说一个字或行其输出讲anything.For例如:
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the
the da
the head
the bed
the bedding
the heading of
the bedding and
the bedding and
the bedding and
the bedding and
the bedding and
the bedding and
the bedding and
the bedding and
the bedding and
the bedding and
the bedding and
the bedding and
the bedding and well
the bedding and well
the bedding and well
the bedding and butler
the bedding and what lingus
the bedding and what lingus
the bedding and what lingus
the bedding and what lingus ha
the bedding and blessed are
the bedding and blessed are
the bedding and what lingus on
the bedding and what lingus want
the bedding and what lingus want
the bedding and what lingus want
the bedding and what lingus want
the bedding and what lingus want or
the bedding and what lingus want to talk
the bedding and what lingus current top
the bedding and what lingus want to talk
the bedding and what lingus want to talk
the bedding and what lingus want to talk
the bedding and what lingus want to talk
the bedding and what lingus want to talk to her
the bedding and what lingus want to talk to her
the bedding and what lingus want to talk to her
the bedding and what lingus want to talk to her
请帮助我通过它。我只是一个Python新手。
谢谢你的回答。但是这段代码对兄弟来说太没有帮助了。它永远不会在语言中识别单词“前进”,而只是在我对它说话时打印随机单词。是否有什么我在模型中缺少的东西? – TechieBoy101
所有这一切意味着pocketsphinx的“翻译”对于您输入的数据而言并不十分准确。因此,正如我指出的那样,在pocketsphinx正确识别您的单词之前,您将不得不尝试几次(多次)。我明白这是多么令人不满。然后,您需要查看**增加识别的准确性,**正确**执行“热门词汇收听”。这些链接在我原来的答案中提供。 –