RecognizerIntent 不起作用; “缺少额外的呼叫包”

发布于 2024-10-12 08:31:57 字数 1570 浏览 7 评论 0原文

我在 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。如果这个额外的 由除系统进程之外的任何人设置, 它应该被声音覆盖 搜索实现。

据我所知,我不需要覆盖这个额外的内容,那么为什么我会收到此错误?我该如何修复我的代码?

I'm having problems using the RecognizerIntent API on Android 2.2. When I call the API using this code:

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);

which looks like it should work, the search popup says "Unknown problem" on the device and in the logs it states:

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

It looks like the problem is the missing "calling_package" extra; on the RecognizerIntent page it states that this extra is:

The extra key used in an intent to the speech recognizer for voice
search. Not generally to be used by
developers. The system search dialog
uses this, for example, to set a
calling package for identification by
a voice search API. If this extra is
set by anyone but the system process,
it should be overridden by the voice
search implementation.

As far as I can tell, I don't need to override this extra, so why am I getting this error? How can I fix my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

软的没边 2024-10-19 08:31:57

我遇到了完全相同的问题。我正在处理我正在处理的活动中具有 android:launchMode="singleInstance" 的现有代码。这对于语音识别器意图不起作用。我将其更改为 android:launchMode="standard"。现在让我们看看它如何破坏我的程序的其余部分:)

I had the exact same problem. I was working on existing code that had android:launchMode="singleInstance" in the activity I was working on. This will not work for speechrecognizer intent. I changed it to android:launchMode="standard". Now let's see how it breaks the rest of my program :)

暗藏城府 2024-10-19 08:31:57

您的原始代码:

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);

工作正常。我在我的设备(HTC Desire)上对其进行了测试,并通过在 Google 中执行以下查询并浏览源代码,将其与其他开源用途进行了比较。

RecognizerIntent.ACTION_RECOGNIZE_SPEECH
网站:code.google.com

我的 logcat 中的输出行之一如下所示:

01-26 13:28:53.268: INFO/RecognitionController(1459): startRecognition(#Intent;action=android.speech.action.RECOGNIZE_SPEECH;component=com.google.android.voicesearch/.IntentApiActivity;B.fullRecognitionResultsRequest=true;S.android.speech.extra.LANGUAGE_MODEL=web_search;S.calling_package=com.test;end)

使用内置应用程序之一(或下载的应用程序)运行类似的搜索,看看它是否有效(并且不是设备问题等)。 )。

如果工作正常,请将代码放入新的测试项目中,只需将这些行放入 onCreate 中(将结果常量更改为 0),然后查看它是否工作。

Your original code:

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);

Works correctly. I tested it on my device (HTC Desire), and also compared it to other open-source uses, by executing the following query in Google, and browsing the source code.

RecognizerIntent.ACTION_RECOGNIZE_SPEECH
site:code.google.com

One of the output lines in my logcat looks like this:

01-26 13:28:53.268: INFO/RecognitionController(1459): startRecognition(#Intent;action=android.speech.action.RECOGNIZE_SPEECH;component=com.google.android.voicesearch/.IntentApiActivity;B.fullRecognitionResultsRequest=true;S.android.speech.extra.LANGUAGE_MODEL=web_search;S.calling_package=com.test;end)

Run a similar search with one of the built in apps (or downloaded ones), see that it works (and is not a device issue, etc.).

If that works correctly, take the code to a new test project, simply put those lines in the onCreate (Change the result constant to 0), and see if it works.

糖果控 2024-10-19 08:31:57

您是否尝试过自己设置额外的内容?

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
intent.putExtra("calling_package","com.yourpackagename.YourActivityClassName");
startActivityForResult(intent, REQUEST_CODE_VOICE_SEARCH);

这是 使用的方法这段代码类似问题

Have you tried setting the extra yourself?

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
intent.putExtra("calling_package","com.yourpackagename.YourActivityClassName");
startActivityForResult(intent, REQUEST_CODE_VOICE_SEARCH);

This is the approach used by this code and is the suggested solution to a similar issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文