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 different methods (Button event, gesture, life cycle) I can call this method to open a speech input prompt just like I clicked the microphone icon in the Google search field. Good, that’s good.
But now I need to call this method using the command voice. Just like in google now, we say “Ok Google” and the “Enter speech input” prompt appears. I want to do this inside my application. For example, I am in the main action and I say “hear me” and the promptSpeechInput method is called.
How can i do this?
Thanks for the help.