Playing audio

The latest Raspbian image comes with all the sound drivers and utilities installed. The packages that are used belong to ALSA. The Raspberry Pi has no way to record audio as it has no microphone jack, and the GPIO pins are all digital. To record audio using GPIO, we need to use an A/D (analog-to-digital) device or a USB sound device that has a microphone input.

Aplay for audio playback

The following is a pre-installed package that plays WAV files:

cd /tmp 
wget http://goo.gl/Ps3paV 
mv Ps3paV siren.wav 
aplay siren.wav 

OMXPlayer for audio playback

OMXPlayer is not just used to play videos. It also supports the playback of audio files, such as MP3 files, and it will try to use hardware decoding if possible:

 omxplayer audio-test.mp3 ...

Get Raspberry Pi 2 Server Essentials 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.