Hardware Reference
In-Depth Information
What we want to do is compress the audio data by encoding the sound to MP3
or OGG format. This will drastically reduce the file size while keeping the audio
sounding almost identical to the human ear.
Type in the following command to install the LAME encoder (for MP3) and the
Vorbis encoder (for OGG):
pi@raspberrypi ~ $ sudo apt-get install lame vorbis-tools
To encode myrec.wav to myrec.mp3 , use the following command:
pi@raspberrypi ~ $ lame myrec.wav
To encode myrec.wav to myrec.ogg , use the following command:
pi@raspberrypi ~ $ oggenc myrec.wav
Once you have your MP3 or OGG file, you can, of course, delete the original
uncompressed myrec.wav file to save space using the rm command:
pi@raspberrypi ~ $ rm myrec.wav
But wouldn't it be convenient if we could just record straight to an MP3 or OGG file?
Thanks to the ingenious pipeline feature of our operating system, this is easy with
the following command:
pi@raspberrypi ~ $ sox -t alsa plughw:1 -t wav - | lame - myrec.mp3
The line does look a bit cryptic, so let's explain what's going on. The | character
that separates the two commands is called a pipeline, or pipe. It allows us to
chain the standard output stream from one application into the standard input
stream of another application. So in this example, we tell sox not to write the
recording to a file on the SD card, but instead pass on the data to lame , which in turn
encodes the sound as soon as it comes in and stores it in a file named myrec.mp3 .
The lone - characters represent the standard input and standard output streams
respectively. We also specify the -t wav argument, which provides lame with useful
information about the incoming audio data.
For OGG output, we have to use a slightly different command:
pi@raspberrypi ~ $ sox -t alsa plughw:1 -t wav - | oggenc - -o myrec.ogg
You can then play back these formats with sox just like any other file:
pi@raspberrypi ~ $ sox myrec.mp3 -d
 
Search WWH ::




Custom Search