Chapter 18

Executing Voice Actions

What's in this chapter?

Software components for defining and executing voice actions

AlertDialog for voice actions

Multi-turn voice actions

A best guess to minimize recognition failure

Diagnosing recognition failure

Chapter 17 described matching in detail. Android's speech recognizer rarely returns a single result. Instead it returns a list of possible strings that represent what the user might have said. Matching involves comparing those strings with the desired command words your voice user interface (VUI) expects.

If your VUI is simple enough, you can implement matching in the way that Chapter 17 does directly within the receiveWhatWasHeard() method. However, to include features that improve usability and to organize multi-turn voice actions, you can benefit from some additional code that this chapter describes.

The code in this chapter helps organize your VUI into VoiceAction objects and execute them. The code also provides some methods for improving the usability of your VUI by showing how your app can make a best guess and respond when recognition fails. To illustrate these concepts, the code in this chapter creates an improved version of the food dialogue example that Chapter 17 introduced.

Food Dialogue VUI Design

The food VUI design, implemented in Chapter 17, had several flaws:

  • It did not use any indexing, so the app failed to understand commands failed more often than necessary.
  • It didn't have any multi-turn voice actions, so users ...

Get Professional Android Sensor Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.