Chapter 14

Using the Microphone

What's in this chapter?

Recording maximum amplitude and raw audio data

Processing asynchronously

Implementing a clapper

Signal processing to determine volume and frequency

Many Android devices are also phones, and hence provide a microphone to the user. Apps can use the microphone as a sensor to record audio and then analyze the resulting recording.

Many apps might benefit from analyzing the audio recording. For example, an app could detect a clap or a certain sound to help the user communicate a command. Instrument tuners and other utilities are also possible.

This chapter describes how to use the MediaRecorder and AudioRecord APIs to record and analyze audio to detect patterns. It describes some utility classes to help you use the APIs. To demonstrate, this chapter shows how to create several versions of a clapper.

Introducing the Android Clapper

The clapper, shown in Figure 14.1, is a device invented in 1986 that attaches to an electrical socket and turns it on and off in response to a person's claps. You can implement something similar on Android that improves upon the features of the original clapper. Instead of activating an electrical outlet, though, your app may take another action instead.

Figure 14.1 A clapper plugs into the wall and controls turning on and off an electrical socket.

14.1

Table 14.1 shows the different implementations of a clapper ...

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.