问题描述
我需要从麦克风中识别出一些关键字才能关联操作。但是我不太了解如何正确使用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','fr.dict'))
config.set_string('-kws','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)]
我该如何解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)