The Road Trip and Burning Speex files to audio CDs 
Today, I'm going on a road trip, and I would like to listen to
something interesting while driving. In an earlier post,
2004-02-20, I described a "VCR" that I created to
record radio shows. Why not listen to some of the recorded shows
while on the road?
The Radio VCR saves the shows in Speex format, but my car's audio
system, like most, can handle only plain-old audio CDs. Thus I needed
to burn a few CDs from my
Speex files.
It's a three step process:
- Decode Speex format into raw, 16 kHz audio.
- "Upsample" the 16 kHz audio into CD-ready 44.1 kHz audio.
- Burn the 44.1 kHz audio to a CD.
It sounds simple, and it is – once you figure out all
the proper speexdec, sox, and cdrecord settings. To save
you the trouble, here's the script I wrote to automate the
process:
#!/bin/bash
#
# $Id: burn-speex,v 1.3 2004/03/20 15:58:02 thor Exp $
# TGM 2004-03-20
#
# Usage: burn-speex file.spx
# configurationcddevice=3,0,0
speed=8# parse argumentsfile="$1"
shift# preflight checks[ -z "$file" ] && { echo "Usage: burn-speex input.spx"; exit 1; }
[ -f "$file" ] || { echo "No such file: $file"; exit 2; }
[ $(id -u) = 0 ] || { echo 'You must be root to burn a CD. (Use sudo?)';
exit 3; }# create temp file to hold WAV filetmp=$(mktemp /tmp/burn-speex-XXXXXX)
mv "$tmp" "$tmp.wav"
tmp="$tmp.wav"# make sure the temp file is cleaned upcleanup() { rm -f "$tmp"; }
trap cleanup 1 2 3 5 13 15# transcode the speex file into 44.1 kHz WAV fileecho
echo "Transcoding speex file $file into 44.1 kHz WAV format..."
echo
speexdec --stereo "$file" - |
sox -t raw -r 16000 -c 2 -sw - -r 44100 -t wav - resample > "$tmp"# burn the WAV fileecho
echo "Burning CD..."
echo
cdrecord -v -pad -audio -eject speed=$speed dev=$cddevice "$tmp"# clean up and exitcleanupecho
echo Done.exit 0