Android Speech Recognition as a service on Android 4.1 & 4.2

前端 未结 4 2158
一向
一向 2020-11-22 04:22

I have managed to get continuous speech recognition working (using the SpeechRecognizer class) as a service on all Android versions up to 4.1. My question concerns getting i

4条回答
  •  星月不相逢
    2020-11-22 05:13

    If you really want to implement continuous listening without internet connection you need to consider third-party packages, one of them is CMUSphinx, 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 = defaultSetup()
            .setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
            .setDictionary(new File(modelsDir, "lm/cmu07a.dic"))
            .setKeywordThreshold(1e-5f)
            .getRecognizer();
    
    recognizer.addListener(this);
    recognizer.addKeywordSearch(KWS_SEARCH_NAME, KEYPHRASE);
    switchSearch(KWS_SEARCH_NAME);
    

    and define a listener:

    @Override
    public void onPartialResult(Hypothesis hypothesis) {
        String text = hypothesis.getHypstr();
        if (text.equals(KEYPHRASE))
          //  do something
    } 
    

提交回复
热议问题