本文介绍了语音命令关键字监听器在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充的语音命令监听器在我application.Service应该听predefined关键字,如果关键字是口语,应该调用一些方法。

I would like to add voice command listener in my application.Service should listen to predefined keyword and and if keyword is spoken it should call some method.

语音命令识别(激活指令)应该没有发出请求,谷歌语音服务器。

Voice command recognition (activation command) should work without send request to Google voice servers.

我怎样才能做到这在Android?

How can I do it on Android?

感谢张贴一些有用的资源。

Thanks for posting some useful resources.

推荐答案

您可以使用Pocketsphinx来完成这个任务。检查 Pocketsphinx机器人演示例如如何高效地在离线收听的关键字和喜欢的特定命令反应一个关键的一句哦强大的电脑。在code做到这一点很简单:

You can use Pocketsphinx to accomplish this task. Check Pocketsphinx android demo for example how to listen for keyword efficiently in offline and react on the specific commands like a key phrase "oh mighty computer". The code to do that is simple:

您创建一个识别器和只添加关键词识别搜索:

you create a recognizer and just add keyword spotting search:

recognizer = SpeechRecognizerSetup.defaultSetup()
        .setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
        .setDictionary(new File(modelsDir, "lm/cmu07a.dic"))
        .setKeywordThreshold(1e-40f)
        .getRecognizer();

recognizer.addListener(this);
recognizer.addKeyphraseSearch("keywordSearch", "oh mighty computer");
recognizer.startListening("keywordSearch);

和定义一个监听器:

@Override
public void onPartialResult(Hypothesis hypothesis) {
    if (hypothesis == null)
          return;
    String text = hypothesis.getHypstr();
    if (text.equals(KEYPHRASE)) {
      //  do something and restart listening
      recognizer.cancel();
      doSomething();
      recognizer.startListening("keywordSearch");
    }
} 

您可以调整关键字门槛最佳的检测/误报匹配。为提供了理想的检测精度关键字应具有至少3个音节,更好4音节

You can adjust keyword threshold for the best detection/false alarm match. For the ideal detection accuracy keyword should have at least 3 syllables, better 4 syllables.

这篇关于语音命令关键字监听器在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 03:12