Saturday, January 28, 2012

CDs of Shakespeare for (almost) free!

The lovely Carol wants to listen to a few Shakespeare plays for her MFA program, and asked me how to get CDs of them. Yeah, I can hear you now. "CDs? That's so 20th century!"

Two words for you: car stereo. "Ruby," our 2004 Subaru, has a CD player but no mp3 player and no aux input jack. The other thing about the car stereo is that, unlike an iPod, you can't leave it on a bench somewhere. If you're in the car, the car stereo's there.

All-righty then. A search on "twelfth night audio" (no quotes) led me to LibriVox site and the download page for King Lear, which you see at right. As you can see, the play runs about 3½ hours, and there are five mp3 files, one per act.

So far so good, but there are two issues we want to deal with. First, a music CD holds what, 65 or 70 minutes, right? Notice the duration of the various parts of the play:

  • Act 1 – 00:53:42
  • Act 2 – 00:38:56
  • Act 3 – 00:38:38
  • Act 4 – 00:42:54
  • Act 5 – 00:28:52
How do we put these on CDs? Act I goes on one CD. Great, fantastic. Act 2 goes on another -- but that leaves 20 minutes, maybe 30 minutes unused at the end of that CD. But not 38:38 -- not enough time for Act 3! Will Act 4 and Act 5 fit together on a single CD? Maybe.

So that's the first issue. The second issue is, if the CD's in the car stereo and somebody wants to change the CD, then how can you recover your place? If one track is 28 or 42 or 53 minutes long, it's rather a pain. So we want to have track divisions at maybe 10-minute intervals.

So here's what we're gonna do. First, change each mp3 file into a "wav" file. For this, we'll use "lame" (meaning "lame ain't no mp3 encoder"). Then we'll use the compact "snd" together with "sox" to split the "wav" files into 10-minute pieces. The plan then would be to put these onto CDs as follows:

  1. Act 1 + 12 minutes of act 2
  2. about 27 minutes of act2 + act 3
  3. acts 4 and 5
Well, we'll see how that works out. So after downloading all the mp3s, we convert them to wavs by typing:
lame --decode Downloads/king_lear_1_shakespeare.mp3 /tmp/k1.wav
and so on for the other 4 files.

Next, we want to divide each of these into (about) ten-minute segments. Where exactly do we divide them, and how? To answer the "where" we'll use snd. You may want to use something else, but "snd" works for me. In the image at left, you can see what looks like a pretty quiet spot about 612 seconds in. The x-axis shows just 611.0 and 613.0 and a bunch of tick-marks; you have to interpolate... well, or you can position the cursor and click, and you'll get a little number near the lower-left corner; you can see it if you enlarge the image -- "612.5030" -- let's just call it 612.5. We'll look for quiet spots around 1200 seconds in, 1800 seconds in, etc., and break the ".wav" file at those points.

But one thing at a time. Given the first break-point, at 612.5 seconds, I type:
sox /tmp/k1.wav -c 2 Desktop/k1.1.wav trim 0 =10:12.5
which is explained as

  • sox
    the program name.
  • /tmp/k1.wav
    the input file
  • -c 2
    Make the output have two channels (stereo) as CDs have
  • Desktop/k1.1.wav
    the output file
  • trim 0 =10:12.5
    Trim 0 off the front, and everything past 10:12.5 (612.5 seconds) from the start.
The next breakpoint looks to be about 1206.2 seconds, which is 20:06.2 so I'll type
sox /tmp/k1.wav -c 2 Desktop/k1.2.wav trim 10:12.5 =20:06.2
and so on for the rest of the 53-minute act. Here are the files for Act I:
collin@p3:/mnt/home/collin> ls -o /tmp/k1.wav; ls -o Desktop/k1.*.wav
-rw-r--r-- 1 collin 284258442 2012-01-23 20:30 /tmp/k1.wav
-rw-r--r-- 1 collin 108045044 2012-01-23 20:48 Desktop/k1.1.wav
-rw-r--r-- 1 collin 104728724 2012-01-27 21:08 Desktop/k1.2.wav
-rw-r--r-- 1 collin 107039564 2012-01-27 21:18 Desktop/k1.3.wav
-rw-r--r-- 1 collin 103723244 2012-01-27 21:19 Desktop/k1.4.wav
-rw-r--r-- 1 collin  85906844 2012-01-27 21:20 Desktop/k1.5.wav
-rw-r--r-- 1 collin  59073640 2012-01-27 21:20 Desktop/k1.6.wav
You may wonder why it is that the six files come to about 56 Mbytes whereas the original /tmp/k1.wav was closer to 28 Mbytes; it's because the output files are stereo, which I think we need for recording on CDs.

I do the same with the rest of King Lear's ".wav" files, aiming for 66 minutes (my guess for how much will fit on a blank CD) on each. The last CD has over 70 minutes, but it still just might fit -- I'm finding out now.

For actually burning the CDs, well, my CD-writer is broken, so I'm using a mac mini, which belongs to the lovely Carol. It's pretty easy to do on a Mac using iTunes (we are running OS X 10.6). Here are the steps:

  1. File → Add to Library
    then select the files (in this case k1.1.wav up to k5.3.wav
  2. Select 65-70(?) minutes' worth of tracks, then File → New playlist from selection
    Then name each playlist
  3. right-click on a playlist and "burn CD from playlist"
And Bob's yer uncle. To summarize, we
  • get free MP3 files from librivox (or wherever);
  • convert to 44.1khz stereo WAV files using lame
  • Separate into tracks (if needed) using snd and sox
  • import into iTunes
  • create iTunes playlists
  • burn CD image using iTunes

2 comments:

Emmanuel said...

Hi Collin. I've been longing to contact you. You wouldn't know how hard I tried to get this blog. I sent a text to your collin@corp.hp.com via my gmail but the mailer reported a permanently failed attempt. Pls how can I contact you? Thanks.

Collin said...

I'm not at HP any more. Leave a comment with your email address and with whatever question/comment you have and I'll get back to you.