我编写了一个小应用程序,允许用户通过按钮选择他使用语音搜索的语言,而不是依赖用户的语言偏好(有时您希望在不将整个 UI 切换为日语的情况下用日语进行语音搜索)。
我正在我的 HTC Desire /Android 2.1 (Softbank-x06ht) 上测试该应用程序。但是,当我调用语音 api 时,我得到一个“连接失败”对话框 [重试/取消],并且 LogCat 显示此警告:
09-12 11:26:13.583: INFO/RecognitionService(545): ssfe url=http://www.google.com/m/voice-search
09-12 10:49:45.683: WARN/RecognitionService(545): required parameter 'calling_package' is missing in IntentAPI request
请注意,我可以使用 Google Voice Search 应用程序,它可以正常工作。
根据 API Docs http://developer.android.com/reference/android/speech/RecognizerIntent.html#EXTRA_CALLING_PACKAGE开发人员不能使用calling_package 参数。好吧,如果是这样,为什么日志说它丢失了?
我试图自己提供参数,但它根本没有改变结果。
private static final String TRIVOICE_CALLING_PACKAGE = "calling_package";
private void callSpeechWebSearch (String language) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,
language);
intent.putExtra(TRIVOICE_CALLING_PACKAGE,
"org.filsa.trivoice");
//intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
try {
startActivity(intent);
} catch (ActivityNotFoundException anfe) {
makeToast("ANFE:" +anfe.getMessage());
}
}