【发布时间】:2021-08-10 16:09:32
【问题描述】:
我在 Android 2.2 上使用 RecognizerIntent API 时遇到问题。当我使用此代码调用 API 时:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
startActivityForResult(intent, REQUEST_CODE_VOICE_SEARCH);
看起来它应该可以工作,搜索弹出窗口在设备上显示“未知问题”,并在其状态的日志中显示:
01-17 14:25:30.433: ERROR/RecognitionActivity(9118): ACTION_RECOGNIZE_SPEECH intent called incorrectly. Maybe you called startActivity, but you should have called startActivityForResult (or otherwise included a pending intent).
01-17 14:25:30.433: INFO/RecognitionControllerImpl(9118): startRecognition(#Intent;action=android.speech.action.RECOGNIZE_SPEECH;launchFlags=0x800000;component=com.google.android.voicesearch/.IntentApiActivity;B.fullRecognitionResultsRequest=true;S.android.speech.extra.LANGUAGE_MODEL=free_form;end)
01-17 14:25:30.433: INFO/RecognitionControllerImpl(9118): State change: STARTING -> STARTING
01-17 14:25:30.443: ERROR/RecognitionControllerImpl(9118): required extra 'calling_package' missing in voice search intent
01-17 14:25:30.443: ERROR/RecognitionControllerImpl(9118): ERROR_CLIENT
01-17 14:25:30.443: ERROR/RecognitionControllerImpl(9118): ERROR_CLIENT
看起来问题是缺少额外的“calling_package”;在 RecognizerIntent 页面上,它指出这个额外的内容是:
语音识别器意图中使用的额外密钥 搜索。一般不被使用 开发商。系统搜索对话框 例如,使用它来设置一个 调用包进行识别 语音搜索 API。如果这个额外是 由系统进程以外的任何人设置, 它应该被声音覆盖 搜索实现。
据我所知,我不需要覆盖这个额外的,那么为什么会出现这个错误?如何修复我的代码?
【问题讨论】:
-
"除了系统进程之外的任何人" - 你的不是需要自己实现的系统进程吗?
-
你从哪里调用 startActivityForResult()?另外,您在哪个设备上看到此问题?最后,您的 Google Voice 识别设置是什么?
标签: android speech-recognition