CMUSphinx在pocketsphinx引擎中实现了关键字识别,详细参见常见问题解答条目。
要识别单个关键词,您可以在“关键词搜索”模式下运行解码器。
从命令行尝试:
pocketsphinx_continuous -infile file.wav -keyphrase “oh mighty computer” -kws_threshold 1e-20
从代码来看:
ps_set_keyphrase(ps, "keyphrase_search", "oh mighty computer");
ps_set_search(ps, "keyphrase_search);
ps_start_utt();
/* process data */
您还可以在我们的源代码中找到 Python 和 Android/Java 的示例。 Python 代码如下所示,完整示例here:
# Process audio chunk by chunk. On keyphrase 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 ([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()])
print ("Detected keyphrase, restarting search")
decoder.end_utt()
decoder.start_utt()
必须针对测试数据上的每个关键短语调整阈值,以获得漏检和误报之间的适当平衡。您可以尝试 1e-5 到 1e-50 等值。
为了获得最佳准确性,最好使用 3-4 个音节的关键短语。太短的短语很容易混淆。
您还可以搜索多个关键词,创建一个文件 keyphrase.list,如下所示:
oh mighty computer /1e-40/
hello world /1e-30/
other_phrase /other_phrase_threshold/
并在带有 -kws 配置选项的解码器中使用它。
pocketsphinx_continuous -inmic yes -kws keyphrase_list
sphinx4 解码器尚未实现此功能。