提问人:Manish Singh Chouhan 提问时间:4/14/2022 更新时间:5/31/2022 访问量:772
SpeechRecognizerListener 在 onResults(Bundle results) 中提供 Bundle[EMPTY_PARCEL] 大多数具有 Android 11 的设备
SpeechRecognizerListener giving Bundle[EMPTY_PARCEL] in onResults(Bundle results) majority devices which have android 11
问:
我正在使用
speech = SpeechRecognizer.createSpeechRecognizer(getReactApplicationContext().getApplicationContext());
speech.setRecognitionListener(VoiceAppModule.this);
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 100000000);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.languageacademy");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 10000);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 10000);
上述用于语音识别的代码。
@Override public void onResults(捆绑结果) {
在 About On Result 中,结果在 Result 中给出了 Bundle[EMPTY_PARCEL]。
ArrayList 匹配 = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
我在许多设备中尝试过,它主要是在具有 android 11 的 MI 手机和一些三星手机中出现问题。
答:
同样的问题在这里,这个错误几天前开始发生。
我认为这个错误的原因是新版本的“Google” 应用 (https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox),因为 SpeechRecognizer 使用此应用来识别语音。
如果您单击uinstall “Google” 应用程序,它将回滚到旧版本,onResult 回调将正常工作。
解决我问题的解决方案是删除:extrasEXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS
Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!
https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SEGMENTED_SESSION
评论
我确认了 Seba 给出的答案,只是在我的情况下,我还必须删除
RecognizerIntent.EXTRA_MAX_RESULTS RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS
并且还影响了装有Android 9的华为和三星设备,因此问题似乎每天都在传播。
我也面临同样的问题。删除以下意图后,它开始工作。
putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 3000)
以前的意图:
recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en")
putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, packageName)
putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH
)
putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 3000)
putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1)
}
修改意图:
recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en")
putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, packageName)
putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH
)
putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1)
}
评论