I have working solution for voice recognition and saving the audio file, but the code works only on some devices.
I have tried running this code on few devices. It seems that this solution works on android 5.0, but doesn't work on higher versions.
I'm using Intent class to do that:
System.out.println("startVoiceInput");
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Hello, How can I help you?");
intent.putExtra("android.speech.extra.GET_AUDIO_FORMAT", "audio/AMR");
intent.putExtra("android.speech.extra.GET_AUDIO", true);
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
a.printStackTrace();
}
Recognition itself works on every device (without those lines:
intent.putExtra("android.speech.extra.GET_AUDIO_FORMAT", "audio/AMR");
intent.putExtra("android.speech.extra.GET_AUDIO", true);
).
But with that lines, necessary to catch audio stream to save it on device, the google popup doesn't appear. I don't get any error, but this log:
D/ViewRootImpl@e232f4[RecordingActivity]: ViewPostIme pointer 0
D/ViewRootImpl@e232f4[RecordingActivity]: ViewPostIme pointer 1
I/System.out: startVoiceInput
D/ViewRootImpl@e232f4[RecordingActivity]: MSG_WINDOW_FOCUS_CHANGED 0
I/System.out: onActivityResult
D/ViewRootImpl@e232f4[RecordingActivity]: Relayout returned: old=[0,0][1080,1920] new=[0,0][1080,1920] result=0x1 surface={valid=true 527892242432} changed=false
MSG_WINDOW_FOCUS_CHANGED 1
V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@4dc5d3e nm : com.example.acces ic=null
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus