Speech recognition listener doesn't work in Galaxy SII

寵の児 提交于 2019-12-04 12:13:38
Leap Bun

I found the solution.

Change the parameter of speechRecognizer.startListening() method to intent as below:

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getApplication().getPackageName());
    speechRecognizer.startListening(intent);

Change the parameters you are passing with the intent

{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

 intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");

 intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                this.getPackageName());

 intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

 intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);

    if (speech != null) {
            speech = null;

        }

        SpeechRecognizer speech SpeechRecognizer.createSpeechRecognizer(this);

        speech.setRecognitionListener(this);

        speech.startListening(intent);

}

Also Check which type of error you are getting for nomatch,network and server error call startListening again

    public void startListening() {
    try {

        if (SpeechRecognizer.isRecognitionAvailable(this)) {
            if (speech != null) {
                speech.startListening(intent);

            } else {
                SimpleMethod();
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!