1

我正在使用 Android 中的 SpeechRecognizer 类在 android 中实现持续语音识别。我的问题是,有时识别的开始(触发意图和获得 onReadyForSpeech 回调之间的时间)需要很长时间。在少数情况下超过 1 分钟!

有人知道这个问题吗?

开始识别:

    Intent recognizerIntent = new Intent(
            RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 

    SpeechRecognitionUtil.recognizeSpeechDirectly(context,
            recognizerIntent, this, getSpeechRecognizer());

private SpeechRecognizer getSpeechRecognizer() {
    if (recognizer == null) {
        recognizer = SpeechRecognizer.createSpeechRecognizer(context);
    }
    return recognizer;
}

public static void recognizeSpeechDirectly(Context context,
        Intent recognizerIntent, RecognitionListener listener,
        SpeechRecognizer recognizer) {
    // need to have a calling package for it to work
    if (!recognizerIntent.hasExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE)) {
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                "com.dummy");
    }

    recognizer.setRecognitionListener(listener);
    recognizer.startListening(recognizerIntent);
}

有时会在开始识别大约一分钟后调用以下回调!

@Override
public void onReadyForSpeech(Bundle params) {}

日志

06-24 20:18:28.266: I/WordActivator(26139): recognizeSpeechDirectly
06-24 20:18:51.091: D/WordActivator(26139): ready for speech Bundle[mParcelledData.dataSize=4]
4

0 回答 0