CMUSphinx 在 pocketsphinx 引擎中实现关键字识别,详细信息请参阅FAQ 条目。
\n\n要识别单个关键词,您可以在 \xe2\x80\x9ckeyphrase search\xe2\x80\x9d 模式下运行解码器。
\n\n从命令行尝试:
\n\npocketsphinx_continuous -infile file.wav -keyphrase \xe2\x80\x9coh mighty computer\xe2\x80\x9d -kws_threshold 1e-20\nRun Code Online (Sandbox Code Playgroud)\n\n从代码来看:
\n\n ps_set_keyphrase(ps, "keyphrase_search", "oh mighty computer");\n ps_set_search(ps, "keyphrase_search);\n ps_start_utt();\n /* process data */\nRun Code Online (Sandbox Code Playgroud)\n\n您还可以在我们的源代码中找到 Python 和 Android/Java 的示例。Python 代码如下所示,完整示例如下:
\n\n# Process audio chunk by chunk. On keyphrase detected perform action and restart search\ndecoder = Decoder(config)\ndecoder.start_utt()\nwhile True:\n buf = stream.read(1024)\n if buf:\n decoder.process_raw(buf, False, False)\n else:\n break\n if decoder.hyp() != None:\n print ([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()])\n print ("Detected keyphrase, restarting search")\n decoder.end_utt()\n decoder.start_utt()\nRun Code Online (Sandbox Code Playgroud)\n\n必须针对测试数据上的每个关键短语调整阈值,以获得漏检和误报之间的适当平衡。您可以尝试 1e-5 到 1e-50 等值。
\n\n为了获得最佳准确性,最好使用 3-4 个音节的关键短语。太短的短语很容易混淆。
\n\n您还可以搜索多个关键词,创建一个文件 keyphrase.list,如下所示:
\n\n oh mighty computer /1e-40/\n hello world /1e-30/\n other_phrase /other_phrase_threshold/\nRun Code Online (Sandbox Code Playgroud)\n\n并在带有 -kws 配置选项的解码器中使用它。
\n\n pocketsphinx_continuous -inmic yes -kws keyphrase_list\nRun Code Online (Sandbox Code Playgroud)\n\nsphinx4 解码器尚未实现此功能。
\n