我正在使用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) {}
LOG
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]