Voice command keyword listener in Android

我怕爱的太早我们不能终老 提交于 2019-11-26 16:39:04

问题


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.

How can I do it on Android?

Thanks for posting some useful resources.


回答1:


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);

and define a listener:

@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");
    }
} 

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.



来源:https://stackoverflow.com/questions/24321893/voice-command-keyword-listener-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!