Python Pocketsphinx关键字解码器

时间:2020-08-11 14:04:14

标签: python voice-recognition decoder pocketsphinx

我需要从麦克风中识别出一些关键字才能关联操作。但是我不太了解如何正确使用Pocketsphinx解码器。这是我的代码,主要来自ctrl + C / ctrl + V ;-) ...老实说,我不了解所有内容。

import os
import pyaudio
from pocketsphinx import DefaultConfig, get_model_path, get_data_path, Decoder

model_path = get_model_path()
data_path = get_data_path()

config = DefaultConfig()
config.set_string('-hmm', os.path.join(model_path, 'fr-fr'))
config.set_string('-dict', os.path.join(model_path,'fr.dict'))
config.set_string('-kws',os.path.join(model_path,'commande.list')) ##file with my keywords
decoder = Decoder(config)

p=pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
stream.start_stream()

decoder.start_utt()

while True:
    buf = stream.read(1024)
    if buf:
         decoder.process_raw(buf, False, False)
    else:
         break
    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()

我看过使用Speech_recognition.Microphone()作为源代码并进行环境噪声校准的代码。 然后音频= r.listen(source) 但是我不知道如何在音频中使用解码器。有人可以帮我吗

我还有两个相似的关键字,例如“ coder”和“ decoder”。当我说“编码器”时可以,但是当我说“解码器”时,结果是:

[('coder ', -1387, 965, 996), ('decoder ', -1362, 939, 996)]

我该如何解决?

0 个答案:

没有答案