我從網站複製代碼聽特定字詞使用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正確識別您的單詞之前,您將不得不嘗試幾次(多次)。我明白這是多麼令人不滿。然後,您需要查看**增加識別的準確性,**正確**執行「熱門詞彙收聽」。這些鏈接在我原來的答案中提供。 –