4

With this code:

private void promptSpeechInput() {
    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,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}

With differents ways (Button event, gesture, life cycle) I can call this method to open the Speech Input prompt as the same way like I've clicked in the microphone icon in the google search field. Ok, that's good.

But now, I need to call this method using a command voice. As the same way in google now, we say "Ok Google" and the Speech Input prompt appears. I want to do this inside my app. For example, I'm in the main activity and I say "hear me" and the method promptSpeechInput is called.

How can I do this?

Thanks for help.

2 Answers2

3

To my knowledge, you can't declare your own wake words -- you're stuck with OK Google. You can use the Voice Actions API referenced by LychmanIT, but that will only handle intents AFTER saying OK Google.

CMUSphynx may be worth looking into. It lets you define custom listeners, but isn't a Google-sanctioned solution for this workflow, so it may not be suitable for you, depending on your requirements. I've had some success prototyping with it though -- it works pretty well.

  • Thank you @SimonPhoenix, this seems to be helpful for me. I will create a test project using it and I and I come to warn you. – Bruno Bertelli Sep 02 '16 at 19:26
1

Through the Voice Actions API, your app can register for system actions, one of which is 'search' (so you could do 'search for Some Question or command on APP').

In the past, some developers were able to submit a custom voice action request. Upon approval, users could do a specific action with your app via voice. This is no longer an option.

LychmanIT
  • 695
  • 6
  • 13
  • Thank you @LychmanIT, I've tested it and this works fine. Isn't the best way for the solution that I thought but I can do this: I can enable 'Ok Google' in all screens. When user are in app, he can do a search using google now, and i can get this command and call an method. Seems to be not a beautiful solution, but user can operate aplication using only voice command. – Bruno Bertelli Sep 02 '16 at 19:39
  • I've created a test project and I have a problem. The search works fine using English language, but I'm from Brazil, and the search isn't working even for YouTube. So, I will try other way. – Bruno Bertelli Sep 02 '16 at 19:40
  • Yes, its seems @Simon_Phoenix`s option is better than mine. Good luck :) – LychmanIT Sep 02 '16 at 19:59