A voice recognition sample
- Receive a request for voice recognition
- Check the availability of application for speech recognizing
- If speech recognizing is available, then call the intent for it and receive the results
- If speech recognizing is not available, then show the dialog for installing Google Voice Search and redirect the user to Google Play, if he wants
As you can see, besides the run() function we need to implement three other functions:
- isSpeechRecognitionActivityPresented – checks if the speech recognition application is present on the system
- installGoogleVoiceSearch – initializes the Google Voice Search installation process
- startRecognition – prepares the appropriate Intent and runs the recognition
Now implement the startRecognition function. This function will form the appropriate Intent for launching the speech recognition Activity. You can find detailed information for how to do it on documentation page.
And last, we’ll implement the installGoogleVoiceSearch. This function will show the dialog, asking the user if he wants to install Google Voice Search and send him to Google Play, if he does.
That’s about it. We run the speech recognition Activity. Then request the user’s permission to install Voice Search and send him to Google Play if he consents. One thing we still need to do and that is gather the voice recognition results.
Now we’re ready
The created class SpeechRecognitionHelper allows us to perform a speech recognition request by calling only one function run().