Chapter 16

Using Speech Recognition and Text-To-Speech APIs

What's in this chapter?

Using the Text-To-Speech and Speech Recognition APIs

Checking for device compatibility and language support

Using reusable helper classes

Using Text-To-Speech and Speech Recognition together

Speech recognition enables users to speak to their Android device and Text-To-Speech (TTS) enables the device to speak back. This chapter explores how to use the speech recognition and TTS APIs and how to properly handle the details of initializing and executing their various functions. In addition, this chapter describes code you can reuse to handle common procedures.

Text-To-Speech

To use TTS, apps must perform the following steps:

1. Initialize the TextToSpeech object. Verify that the device supports the desired language, download additional data if necessary, and wait for an asynchronous TTS engine initialization process to complete.
2. Operate the TextToSpeech API to play speech, sounds, and silence.
3. Implement an Activity that handles managing the TextToSpeech life cycle as well as any user interactions that are required during initialization or speaking.

This chapter presents an implementation of TextToSpeech that involves several classes. The classes implement two groups of functionality: initializing and using TTS. The design implements these with three classes and an interface between two of them. Specifically, here are the classes and their functions:

  • TextToSpeechStartupListener: An interface containing ...

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.