本文介绍了语音识别听众不GALAXY SII工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing an Android application which always listen voice from user. It works when I run it on Sony X10i, but doesn't work in Samsung Galaxy SII.Here is my code:

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

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

In this case, how to solve this problem?

推荐答案

我找到了解决办法。

speechRecognizer.startListening()方法的参数更改为意图如下:

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

这篇关于语音识别听众不GALAXY SII工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 00:49