Pergunta

Estou tentando trabalhar e testar um exemplo de reconhecimento de voz baseado no exemplo de voz. http://developer.android.com/resources/samples/apidemos/src/com/example/android/apis/app/voicecognition.html

Mas ao clicar no botão para criar a atividade, recebo uma caixa de diálogo que diz um problema de conexão. Meu arquivo de manifesto está usando a permissão da Internet e entendo que ele passa para os servidores do Google. Eu preciso fazer qualquer outra coisa para usar isso. Código abaixo

ATUALIZAÇÃO 2: Graças a Steve, pude instalar o driver USB e depurar o aplicativo diretamente no meu dróide. Aqui está a saída do logcat ao clicar no meu botão de microfone:

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)

A linha que me preocupa é o aviso do pacote de chamadas de parâmetros ausentes.

ATUALIZAÇÃO: OK, pude substituir minha imagem do emulador por uma da HTC que parece vir com a pesquisa de voz do Google, no entanto, agora quando eu corro do emulador, estou recebendo uma mensagem de problema de áudio com os botões Speak Again ou Cancel. Parece voltar ao OnactivityResult (), mas o código de resultado é 0.

Aqui está a saída 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

Ainda não sei por que estou recebendo o problema de conexão no dróide. Eu posso usar a pesquisa de voz OK. Eu também tentei limpar o cache e os dados descritos em algumas postagens, mas não funcionando?

/**
* 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);
}
Foi útil?

Solução

Ok ... problema corrigido.

Parece que você não pode usar o Android: soundmode = "singleInstance" ao usar o reconhecedorIntent. Eu removi isso do manifesto e a pesquisa de voz é executada corretamente.

Mais uma vez obrigado Steve, pelas informações sobre a depuração USB no dispositivo. Muito conveniente.

Outras dicas

Você também pode usar android:launchMode="singleTask"

Funciona bem com vs.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top