Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Google Keep "get audio" extras #34

Open
Kaljurand opened this issue Apr 9, 2015 · 20 comments
Open

Support Google Keep "get audio" extras #34

Kaljurand opened this issue Apr 9, 2015 · 20 comments

Comments

@Kaljurand
Copy link
Owner

Original issue 30 created by Kaljurand on 2014-01-24T09:56:24.000Z:

Support extras:

  • android.speech.extra.GET_AUDIO_FORMAT: audio/AMR
  • android.speech.extra.GET_AUDIO: true

used by Google Keep.

@Kaljurand
Copy link
Owner Author

Comment #1 originally posted by Kaljurand on 2014-11-19T23:13:48.000Z:

v0.8.44 supports audio/wav

@Kaljurand
Copy link
Owner Author

Comment #2 originally posted by Kaljurand on 2014-12-10T11:52:29.000Z:

Please provide the support of these extras!

@Kaljurand
Copy link
Owner Author

Comment #3 originally posted by Kaljurand on 2014-12-10T12:39:44.000Z:

Hey...are you able to save the wav formatted audio? if yes then how?

@Kaljurand
Copy link
Owner Author

Comment #4 originally posted by Kaljurand on 2014-12-10T13:58:41.000Z:

@pavan.kirusa

See this Stackoverflow answer for how to get the audio data out of the result intent: http://stackoverflow.com/a/24404235/12547

@Kaljurand
Copy link
Owner Author

Comment #5 originally posted by Kaljurand on 2014-12-10T14:04:03.000Z:

Using that code my demo app is not launching the Google search's microphone prompt

@Kaljurand
Copy link
Owner Author

Comment #6 originally posted by Kaljurand on 2014-12-10T14:05:36.000Z:

I was trying same code but by putting these extras my demo app is not even launching the Google search's microphone prompt. Does it need any kind of permissions apart from Record Audio...?

@Kaljurand
Copy link
Owner Author

Comment #7 originally posted by Kaljurand on 2014-12-10T14:20:01.000Z:

Thanks man I'm able to receive the AMR format..but as you have mentioned above about the audio/wav format....I'm trying that and its not working

@Kaljurand
Copy link
Owner Author

Comment #8 originally posted by Kaljurand on 2014-12-10T14:21:30.000Z:

Thanks man I'm able to receive the AMR format..but as you have mentioned above about the audio/wav format....I'm trying that and its not working..are you able to receive the wav formatted audio?

@Kaljurand
Copy link
Owner Author

Comment #9 originally posted by Kaljurand on 2014-12-10T19:01:30.000Z:

@pavan.kirusa Currently, Kõnele does not return AMR, but WAV. If your question is not about Kõnele, then please use another forum. If it is then please post the code that is not working, and I can take a closer look.

@Kaljurand
Copy link
Owner Author

Comment #10 originally posted by Kaljurand on 2014-12-11T09:04:22.000Z:

I'm running the code you suggested through the stackoverflow answer using Konele as the input for voice with only one change AMR to WAV

@Kaljurand
Copy link
Owner Author

Comment #11 originally posted by Kaljurand on 2014-12-13T23:47:54.000Z:

@pavan.kirusa

See the ExtrasDemo in the Kõnele settings, and the corresponding source code. It gets the audio URI by calling getData() on the resulting intent. You just have to save the data referenced by this URI.

@Kaljurand
Copy link
Owner Author

@ismtlee This toast is not generated by Kõnele, but by an external app that one can (optionally) use via Kõnele. It is not possible to suppress toasts generated by external apps, unless of course they offer an API for doing so.

@tungdsv
Copy link

tungdsv commented Oct 12, 2018

Hello,
I used SpeechRecognizer to not show Google microphone but i can't get audio record. I try many methods to capture audio but all of them are not successful.
So, How I can get result text and audio without show Google microphone?
Thanks!

@Kaljurand
Copy link
Owner Author

@tungdsv can you post some code to add more detail to your question?

@tungdsv
Copy link

tungdsv commented Oct 12, 2018

@Kaljurand
My goal is capture audio and text from speech to text but not show Google microphone popup.
This is my code using SpeechRecognizer.

private void onRecordAudioPermissionGranted(Context context) {
        try {
            intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, language);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, language);
            intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, language);
            intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); // For streaming result
            intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, timeout);
            intent.putExtra("android.speech.extra.GET_AUDIO_FORMAT", "audio/AMR");
            intent.putExtra("android.speech.extra.GET_AUDIO", true);

            recognizer = SpeechRecognizer.createSpeechRecognizer(context);
            recognizer.setRecognitionListener(this);
            recognizer.startListening(intent);

        } catch (Exception exc) {
            if (mSpeechCallback != null) {
                mSpeechCallback.onError(exc.getMessage());
            }
        }
    }

And this above code I can't get audio from RecognitionListener.
After, I use MediaRecorder or AudioRecord to record audio when startlistenning(). However, whenever start recording, SpeechRecogziner immediately return result is empty and finish listenning.
I tried using SpeechReconginze in activity and recorder in thread or service but same result. Then using SpeechRecognize in thread or service and Recorder in activity but same result.
If i use the below code, i can capture text and audio from OnAcitivtyResult but it show Google Microphone popup:

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, language);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, language);
        intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, language);
        intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); // For streaming result
        intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, timeout);
        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) {
            Toast.makeText(getApplicationContext(),
                    getString(R.string.speech_not_supported),
                    Toast.LENGTH_SHORT).show();
        }

But this is not my goal.
Could you help me or suggest for me a solution?
Thank you!

@Kaljurand
Copy link
Owner Author

@tungdsv I don't know how the Google service returns audio. This is out of the scope of the Kõnele project. You should ask Google.

@tungdsv
Copy link

tungdsv commented Oct 13, 2018

@Kaljurand
Thank you!
So, the Kõnele project allow capture audio and text from speech to text?

@Kaljurand
Copy link
Owner Author

@tungdsv Kõnele can be used as a front-end to 3rd party speech-to-text services. It depends on these services if they return the audio as well, or just text. However, Kõnele also comes with its own services ("grammar support" and "fast recognition"), and they return the audio (as wav), try it out in "Developer settings ... -> Extras demo". (This issue is about adding AMR support.)

@tungdsv
Copy link

tungdsv commented Oct 15, 2018

@Kaljurand
I download project and run app. In extra demo, in chat demo, I see when speech to text no dialog shown.
My question is I can get audio (wav) in chat demo?
If can, how i can capture audio?
Thanks!

@Kaljurand
Copy link
Owner Author

You would need to implement the onBufferReceived-callback and hope that the service fills the buffer with the actual audio:

        @Override
        public void onBufferReceived(byte[] buffer) {
            // save the buffer for later
        }

See e.g.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants