a blog about things that I've been thinking hard about

How to Create an Audio CD Using SoX and InfraRecorder

23 January, 2008
use Sox and InfraRecorder to create an audio CD

Record your .WAV files.

Possibly convert them to required format using SoX.

(The required format is signed integer, 16 bit, 44100 Hz sample rate, stereo.)

Burn the CD using InfraCorder.

tags:

Motivation

I had recorded a large number (112 to be exact) of small WAV files on my Philips MP3 player, and I wanted to write them to an Audio CD. I found that this process was either impossible or not straightforward with any of the commercial software installed on my computer, including Windows Media Player (although I later found this advice on how to deal with the problem that Windows Media Player v11 doesn't just let you point to a directory full of files and say "burn these!").

So I decided that I should be able to use open source software to do the job.

I read that InfraRecorder can write Audio CDs. However, when I attempted to write a CD from my recorded WAV files, I got the following message:

Inappropriate audio encoding in file: '/cygdrive/D/Recorded/Voice/VOICE001.WAV'

i.e. Inappropriate audio encoding in file: '/cygdrive/D/Recorded/Voice/VOICE001.WAV'.

At this point I learned that there is more than one kind of WAV file, and the kind of WAV file I had recorded on my MP3 player was not the kind of WAV file that InfraRecorder was willing to write to a CD.

No doubt future versions of InfraRecorder will include automatic conversion, but for the moment I had to find a way to convert my files.

SoX

The most popular and/or recommended open-source sound conversion utility is SoX, so I downloaded the Windows version of that program.

Unfortunately when InfraRecorder tells you that your WAV files have the wrong encoding, it doesn't tell you what the correct encoding is. So I had to look up information about Audio CD tracks, and relate the details to the Sox options, as described, for example, here.

There turn out to be four relevant characteristics of CD audio files:

Translated into Sox options, this requires a command line such as the following:

sox VOICE001.WAV -s -w -c 2 -r 44100 soxed/VOICE001.WAV

where VOICE001.WAV is the original file and soxed/VOICE001.WAV is the output file.

A Ruby Script to Loop Over the Input Files

Because I had 112 files and because I didn't want to execute a command 112 times, I needed a way to loop over my WAV files. I know you can do it using a Windows batch file, but I prefer to write even simple scripts in a proper programming language, so I used the following Ruby script:

soxExecutable = "c:/Users/MisterPD/bin/sox.exe"

Dir.glob("*.WAV").each do |file|
  command = [soxExecutable, file, "-s", "-w", "-c", "2", 
             "-r", "44100", "soxed/#{file}"]
  puts " #{command.inspect} ..."
  system(*command)
end

(For some reason I got messages like:

c:/Users/MisterPD/bin/sox.exe: Premature EOF on .wav input file

on each file, but the output files seemed to be complete, so I don't know if that message is something that matters at all.)

Burning the CD in InfraRecorder

Having prepared my files, it was then straightforward to burn a CD from InfraRecorder. The main steps to do this are:

Software Versions Used

Vote for or comment on this article on Reddit or Hacker News ...