Good stuff for programming geeks
[ start | index | login or register ]
start > 2004-03-20

2004-03-20

Created by tmoertel. Last edited by tmoertel 1590 days ago. Viewed 1122 times. #4
[diff] [history] [edit] [rdf]
labels
attachments

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:

  1. Decode Speex format into raw, 16 kHz audio.
  2. "Upsample" the 16 kHz audio into CD-ready 44.1 kHz audio.
  3. 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

# configuration

cddevice=3,0,0 speed=8

# parse arguments

file="$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 file

tmp=$(mktemp /tmp/burn-speex-XXXXXX) mv "$tmp" "$tmp.wav" tmp="$tmp.wav"

# make sure the temp file is cleaned up

cleanup() { rm -f "$tmp"; } trap cleanup 1 2 3 5 13 15

# transcode the speex file into 44.1 kHz WAV file

echo 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 file

echo echo "Burning CD..." echo cdrecord -v -pad -audio -eject speed=$speed dev=$cddevice "$tmp"

# clean up and exit

cleanup

echo echo Done.

exit 0

Please login to post a comment.
community.moertel.com | Copyright © 2003–07 Moertel Consulting