Implementing voice recognition
Now that our prototype can handle different presets, we should provide a fast way to change, create, or edit user presets through voice recognition. One of the easiest ways to manage voice recognition is to use Android's Intent
messaging object to delegate this action to another application component. As we discussed at the beginning of the chapter, if we install and configure a compliant voice input application, Android can use it for voice recognition.
The main goal is to provide an abstract class that will be extended by our activities in order to manage recognition callback, while avoiding code repetition. The overall design is as follows:
We should provide a common interface for activities that need voice recognition.
We should provide a
startRecognition()
method to launch the recognition activity through theIntent
object.We should implement the
onActivityResult()
callback that will be called by the launched activity when voice recognition ends. In this...