Voice interface is not a common application user interface, we do not usually interact with application using voice. But when it comes to mobile it makes more sense.
We are used to talk to a phone all day – why not talk to our phone apps?
Not all voice interaction should look like this video:
Here is how you use Android Voice Recognition API:
- Call the RecognizerIntent – your application call the Voice recognition Intent that records the voice.
- Intent processes the voice recording – sends it to the voice Recognition Service and returns
- A list of string is passed to an implemented callback method in you application
- You process the string and continue the interaction with the user
Here is a simple call to the intent:
/**
* Fire an intent to start the speech recognition activity.
*/
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
And here is the callback:
/**
* Handle the results from the recognition activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
// Fill the list view with the strings the recognizer thought it could have heard
ArrayList matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
//DO SOMETHING WITH THE MATCHES
super.onActivityResult(requestCode, resultCode, data);
}
Here is a full code sample – I played with it today and will very little effort created a Pizza ordering application for my next demo session.