Chapter 17

Matching What Was Said

What's in this chapter?

Matching using word spotting

Matching against command words in persistent storage

Matching single and multi-part commands

The previous chapter showed how to use the speech recognition and TTS APIs. The chapter provided code that extracts speech recognition results from onActivityResult() and passes them to the following method:

    abstract protected void receiveWhatWasHeard(
            List<String> heard, float[] confidenceScores);

Your implementation of the abstract receiveWhatWasHeard() method has to decide if your app heard any commands. To do this your implementation must iterate over the recognition results and try to match them with command words. You could implement receiveWhatWasHeard() using a Set<String> that succeeds if any heard strings are in the Set. However, that does not allow you to implement all the types of commands you may want, nor does it allow you to handle all the speech recognition issues that can decrease accuracy.

This chapter reviews the issues involved in reliably matching commands with the user's utterances. Also, this chapter presents a word spotting algorithm for matching and an implementation of it that can match various command types. Word spotting works well for simple commands and the type of information Android returns.

Parts of a Voice Command

Designing commands requires determining what kinds of text the command needs to recognize to activate it and supply information, how many different parts ...

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.