Get audio from voice recognition intent

1k views Asked by At

I followed almost every link for getting audio data in onActivityResult() of RecognizerIntent.

1. Get URI of saved audio in OnResults(Bundle result) in Speech RecognitionListener android
2. record/save audio from voice recognition intent

I follow the same approach, and my code is almost identical. But I am getting a null back from data.getData(); Any help would be very much appreciated.

Here is my code:

    private void startVoiceRecognitionActivity() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

    String language = Locale.US.toString();
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, language);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);

    intent.putExtra("android.speech.extra.GET_AUDIO_FORMAT", "audio/AMR");
    intent.putExtra("android.speech.extra.GET_AUDIO", true);

    startActivityForResult(intent, REQUEST_CODE);
}

   @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        Bundle bundle = data.getExtras();

        // This part works fine.
        ArrayList<String> matches = bundle.getStringArrayList(RecognizerIntent.EXTRA_RESULTS);

        // But audioUri is always null !!!
        Uri audioUri = data.getData();
        ...
}

And in my AndroidManifest.xml file, I have

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


Thank you in advance.

0

There are 0 answers