Chapter 9

Multimedia

IN THE PAST eight chapters, you've seen loads of ways of processing data, and getting it out of the Pi. However, so far you haven't seen many ways of getting data into the Pi. There's been some key and button pressing, and a bit with the mouse, but that's about it. In this chapter, we're going to change that. There are two additional sensors you can give your Pi to allow it to interact with the world in a far more natural way—microphones and cameras. We'll look at each in turn and see how you can use them in your Python programs.

Using PyAudio to Get Sound into Your Computer

There are all manner of things you can do once you have sound in the computer, but they all start with the same process of getting sound in. The module PyAudio is the best one for quickly and simply getting audio into the computer. Once you've captured the audio, you can do whatever you want with it, but if you want to use it in other programs, you'll need some format that other software understands. WAV is a simple lossless format that's great for simple audio data (although it can produce huge files if you're recording a lot of data).

You'll also need a USB microphone to get the sound. The jack port of the Pi is only for sound output.

As always, the first thing you'll need to do is install the modules with the following terminal command:

sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 
\portaudio19-dev python3-setuptools python3-pipsudo pip-3.2 install pyaudio

Now ...

Get Learning Python with Raspberry Pi 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.