语音识别听者不GALAXY SII工作(Speech recognition listener do

2019-07-30 04:12发布

我正在开发一个Android应用程序,它总是从用户听的声音。 它的工作原理,当我在索尼X10i的运行它,但在三星Galaxy SII不起作用。 这里是我的代码:

    SpeechRecognizer     speechRecognizer;
    speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getBaseContext());
    MyRecognitionListener speechListner=new MyRecognitionListener();
    speechRecognizer.setRecognitionListener(speechListner);
    speechRecognizer.startListening(RecognizerIntent.getVoiceDetailsIntent(getApplicationContext()));

这里是我的监听器类:

class MyRecognitionListener implements RecognitionListener {

    public void onBeginningOfSpeech() {
        Log.d("leapkh", "onBeginningOfSpeech");
    }

    public void onBufferReceived(byte[] buffer) {
        Log.d("leapkh", "onBufferReceived");
    }

    public void onEndOfSpeech() {
        Log.d("leapkh", "onEndOfSpeech");
    }

    public void onError(int error) {
        Log.d("leapkh", "onError");
    }

    public void onEvent(int eventType, Bundle params) {
        Log.d("leapkh", "onEvent");
    }

    public void onPartialResults(Bundle partialResults) {
        Log.d("leapkh", "onPartialResults");
    }

    public void onReadyForSpeech(Bundle params) {
        Log.d("leapkh", "onReadyForSpeech");
    }


    public void onResults(Bundle results) {
        Log.d("leapkh", "onResults");

    }

    public void onRmsChanged(float rmsdB) {
        Log.d("leapkh", "onRmsChanged");
    }
}

在这种情况下,如何解决这个问题呢?

Answer 1:

我找到了解决办法。

改变的参数speechRecognizer.startListening()方法来intent如下:

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


Answer 2:

更改您传递的意图参数

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

}

另外,请检查你正在为NOMATCH,网络和服务器错误再次调用startListening的错误类型

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


文章来源: Speech recognition listener doesn't work in Galaxy SII