2010-03-07 69 views
4

I,M試圖通過工作和測試基礎上,VoiceRecognition.java例如語音識別例如在http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html語音識別連接錯誤

但是當點擊該按鈕來創建活動中,我得到一個對話框,說:連接問題。我的Manifest文件正在使用Internet權限,我知道它傳遞給Google服務器。我需要做其他事情來使用它嗎?下面的代碼

更新2: 感謝史蒂夫,我已經能夠安裝USB驅動程序並直接在我的Droid上調試應用程序。下面是從點擊我的麥克風按鈕輸出的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 [email protected] (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中的一個替換我的模擬器圖像,看起來與谷歌語音搜索一起出現,但是現在當我從模擬器運行時,我收到一個Audio Problem消息,或取消按鈕。看來,使其恢復到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 [email protected] 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 

I,M仍然不知道爲什麼I,M上得到連接問題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); 
} 
+0

我建議在這裏粘貼日誌,或者至少是相關的部分。從你的Android工具目錄運行'adb logcat'。不要依賴屏幕上的消息,查看拋出的實際異常或警告輸出。 – 2010-03-07 19:12:44

+0

我實際上是在摩托羅拉Droid上測試這個。我想我認爲這是不可能在模擬器中測試的。 – bugzy 2010-03-07 21:50:54

+0

您也可以從實際的電話獲得調試消息。在菜單 - >設置 - >應用程序 - >開發下,有一個USB調試選項。啓用它,然後當您插入手機時,LogCat(Eclipse內部)將收到您的錯誤消息。 – 2010-03-08 15:28:09

回答

4

好的......問題已修復。

使用RecognizerIntent時看起來不能使用android:launchMode =「singleInstance」。我從清單中刪除了這個,語音搜索運行正常。

再次感謝Steve,瞭解設備上的USB調試信息。非常便利。

1

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

它正常工作與VS.

+0

使用singleTask vs singleInstance有缺點嗎? – 2012-11-04 19:40:49