Kaljurand / K6nele

An Android app that offers speech-to-text user interfaces to other apps
http://kaljurand.github.io/K6nele/
Apache License 2.0
267 stars 83 forks source link

Support Google Keep "get audio" extras #34

Open Kaljurand opened 9 years ago

Kaljurand commented 9 years ago

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

Support extras:

used by Google Keep.

Kaljurand commented 9 years ago

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

v0.8.44 supports audio/wav

Kaljurand commented 9 years ago

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

Please provide the support of these extras!

Kaljurand commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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

tungdsv commented 5 years ago

@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 commented 5 years ago

@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 commented 5 years ago

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

Kaljurand commented 5 years ago

@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 commented 5 years ago

@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 commented 5 years ago

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. https://github.com/Kaljurand/K6nele/blob/863bf5be1e267b5280a697275c2cfbeb19c681c4/app/src/main/java/ee/ioc/phon/android/speak/activity/SpeechActionActivity.java#L210