我正在使用SpeechRecognizer。问题是如果没有活动的互联网连接,SpeechRecognizer会抛出错误SpeechRecognizer.ERROR_NETWORK
或SpeechRecognizer.ERROR_SERVER
。
这是我的RecognizerIntent:
final Intent recognizerIntent;
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);
我尝试使用recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);
,但是没有成功。仍然会抛出相同的错误。
我经常遇到以下两个错误:
SpeechRecognizer.ERROR_RECOGNIZER_BUSY
SpeechRecognizer.ERROR_NO_MATCH
请帮助我。