0

Currently I have working speech recognition but RecognizerIntent.EXTRA_PROMPT is shown as text only on mobile as well as on wearable watch.

Is there any way or other option to make prompt to speak (play as audio)?

Have tried VoiceInteraction API but it is limited to picking an option and have to start through one of the system voice command.

    private static final int SPEECH_REQUEST_CODE = 0;

 // Create an intent that can start the Speech Recognizer activity
    private void displaySpeechRecognizer() {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "How can I help you?");
        // Start the activity, the intent will be populated with the speech text
        startActivityForResult(intent, SPEECH_REQUEST_CODE);
    }

    // This callback is invoked when the Speech Recognizer returns.
    // This is where you process the intent and extract the speech text from the intent.
    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {
        if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
            List<String> results = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            String spokenText = results.get(0);
            Log.d(TAG, "spokenText: " + spokenText);
            // Do something with spokenText
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
Prakash
  • 4,479
  • 30
  • 42

2 Answers2

0

I think you are on track. You have to use Voice Interaction API to have a voice interaction, Google Voice Actions recognizes many spoken and typed action requests and creates Android intents for them.

According to the video recording for Voice interaction API:

Whether your app uses system or custom voice actions, there might be times when the app would like to ask the user a follow-up question before performing the action. For example, after a music app launches when a user says “play some music”, it may want to ask the user “what genre?” Or when a home automation app hears the user say “OK Google, turn on the lights”, it might want to ask “which room?” The Voice Interaction API lets Android M apps ask follow-up questions like these.

In the codelab, you'll learn how to add voice interactions to your app with the Voice Interaction API. The Voice Interaction API allows users of your app to confirm actions and select from a list of options using only their voice.

Note:

The Google Voice Interaction API lets an activity interact with the user using speech to get input that:

  • confirms an action (for example, "are you sure?")
  • selects from a list of options

Helpful References:

Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91
  • Thanks @Mr.Rebot for answers and links. I had tried all these and as of now custom voice is not opened to all yet check https://developers.google.com/voice-actions/custom-actions. And "Android speech to Text" will only prompt text not play as audio. – Prakash Sep 13 '16 at 20:39
0

You first play audio how to play audio file in android

When audio is over, you start speech recognition.

Community
  • 1
  • 1
Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87