我正在使用SpeechRecognizer。问题是如果没有活动的互联网连接,SpeechRecognizer将抛出错误SpeechRecognizer.ERROR_NETWORK
或SpeechRecognizer.ERROR_SERVER
。
这是我的识别器内容
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
请帮帮我。
答案 0 :(得分:0)
首先,您需要确保是否在设备上安装了EXTRA_LANGUAGE_PREFERENCE的离线语言包。
要在支持的设备中启用离线语音输入,请按以下步骤操作:
如果它仍然无法脱机工作,请尝试将您的EXTRA_LANGUAGE_PREFERENCE
值更改为更具体的内容,例如"en-US"
(这对我有用)
而且,如果你想告诉SpeechRecognizer
它应该识别哪种语言,我想你应该使用EXTRA_LANGUAGE
参数代替EXTRA_LANGUAGE_PREFERENCE
希望它会有所帮助