我正在尝试基于 VoiceRecognition.java 示例来研究和测试语音识别示例,网址为 http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html

但是当单击按钮创建活动时,我会看到一个对话框,显示连接问题。我的清单文件正在使用互联网权限,我知道它会将其传递到 Google 服务器。我需要做任何其他事情才能使用这个吗?代码如下

更新2:感谢 Steve,我能够直接在我的 Droid 上安装 USB 驱动程序并调试应用程序。以下是单击我的麦克风按钮后的 LogCat 输出:

03-08 18:36:45.686: INFO/ActivityManager(1017): Starting activity: Intent { act=android.speech.action.RECOGNIZE_SPEECH cmp=com.google.android.voicesearch/.IntentApiActivity (has extras) }

03-08 18:36:45.686: WARN/ActivityManager(1017): Activity is launching as a new task, so cancelling activity result.

03-08 18:36:45.787: DEBUG/NetworkLocationProvider(1017): setMinTime: 120000

03-08 18:36:45.889: INFO/ActivityManager(1017): Displayed activity com.google.android.voicesearch/.IntentApiActivity: 135 ms (total 135 ms)

03-08 18:36:45.905: DEBUG/NetworkLocationProvider(1017): onCellLocationChanged [802,0,0,4192,3]

03-08 18:36:45.951: INFO/MicrophoneInputStream(1429): Starting voice recognition with audio source VOICE_RECOGNITION

03-08 18:36:45.998: DEBUG/AudioHardwareMot(990): Codec sampling rate already 16000

03-08 18:36:46.092: INFO/RecognitionService(1429): ssfe url=http://www.google.com/m/voice-search

03-08 18:36:46.092: WARN/RecognitionService(1429): required parameter 'calling_package' is missing in IntentAPI request

03-08 18:36:46.115: DEBUG/AudioHardwareMot(990): Codec sampling rate already 16000

03-08 18:36:46.131: WARN/InputManagerService(1017): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@4487d240 (uid=10090 pid=3132)

03-08 18:36:46.131: WARN/IInputConnectionWrapper(3132): showStatusIcon on inactive InputConnection

03-08 18:36:46.248: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.334: DEBUG/dalvikvm(3206): GC freed 3682 objects / 369416 bytes in 293ms
03-08 18:36:46.358: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.412: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.444: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.475: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.506: WARN/MediaPlayer(1429): info/warning (1, 44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)
03-08 18:36:46.514: INFO/MediaPlayer(1429): Info (1,44)

我关心的一行是缺少参数调用包的警告。

更新:好的,我能够用 HTC 的模拟器图像替换我的模拟器图像,该图像似乎附带 Google 语音搜索,但是现在当我从模拟器运行时,我收到一条带有“再次发言”或“取消”按钮的音频问题消息。看起来返回到了onActivityResult(),但是resultCode是0。

这是 LogCat 输出:

03-07 20:21:25.396: INFO/ActivityManager(578): Starting activity: Intent { action=android.speech.action.RECOGNIZE_SPEECH comp={com.google.android.voicesearch/com.google.android.voicesearch.RecognitionActivity} (has extras) }

03-07 20:21:25.406: WARN/ActivityManager(578): Activity is launching as a new task, so cancelling activity result.

03-07 20:21:25.968: WARN/ActivityManager(578): Activity pause timeout for HistoryRecord{434f7850 {com.ikonicsoft.mileagegenie/com.ikonicsoft.mileagegenie.MileageGenie}}

03-07 20:21:26.206: WARN/AudioHardwareInterface(554): getInputBufferSize bad sampling rate: 16000

03-07 20:21:26.256: ERROR/AudioRecord(819): Recording parameters are not supported: sampleRate 16000, channelCount 1, format 1

03-07 20:21:26.696: INFO/ActivityManager(578): Displayed activity com.google.android.voicesearch/.RecognitionActivity: 1295 ms

03-07 20:21:29.890: DEBUG/dalvikvm(806): threadid=3: still suspended after undo (s=1 d=1)

03-07 20:21:29.896: INFO/dalvikvm(806): Uncaught exception thrown by finalizer (will be discarded):

03-07 20:21:29.896: INFO/dalvikvm(806): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@435d3c50 on ml_trackdata that has not been deactivated or closed

03-07 20:21:29.896: INFO/dalvikvm(806):     at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)

03-07 20:21:29.896: INFO/dalvikvm(806):     at dalvik.system.NativeStart.run(Native Method)

03-07 20:21:31.468: DEBUG/dalvikvm(806): threadid=5: still suspended after undo (s=1 d=1)

03-07 20:21:32.436: WARN/IInputConnectionWrapper(806): showStatusIcon on inactive InputConnection

我仍然不确定为什么我在 Droid 上遇到连接问题。我可以使用语音搜索。我还尝试清除缓存和一些帖子中描述的数据,但仍然不起作用?

/**
* Fire an intent to start the speech recognition activity.
*/
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}

/**
* Handle the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
  // Fill the list view with the strings the recognizer thought it could have heard
  ArrayList<String> matches = data.getStringArrayListExtra(
  RecognizerIntent.EXTRA_RESULTS);
  mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
matches));
}

super.onActivityResult(requestCode, resultCode, data);
}
有帮助吗?

解决方案

好的...问题已解决。

使用 RecognizerIntent 时,您似乎无法使用 android:launchMode="singleInstance" 。我从清单中删除了它,语音搜索运行正常。

再次感谢 Steve 提供有关设备上 USB 调试的信息。非常便利。

其他提示

您还可以使用 android:launchMode="singleTask"

与 VS 配合使用效果很好。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top