<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Tom Moertel's Weblog: My new Radio VCR</title>
    <link>http://blog.moertel.com/articles/2004/02/20/my-new-radio-vcr</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Quality rants on programming theory and stuff geeks like</description>
    <item>
      <title>My new Radio VCR</title>
      <description>&lt;p&gt;I like to listen to &lt;a href="http://www.npr.org/"&gt;&lt;span class="caps"&gt;NPR&lt;/span&gt;&lt;/a&gt;, but I often miss interesting shows. So I decided to make a &lt;span class="caps"&gt;VCR&lt;/span&gt; for radio. That way I can record shows and listen to them at my leisure.&lt;/p&gt;


	&lt;p&gt;I started by taking an old radio and connecting its headphone output to one of my server&amp;#8217;s audio-in jacks w/ a 6-foot 1/8&amp;#8221; Stereo plug to 1/8&amp;#8221; Stereo plug Cord from Radio Shack. Then I installed the &lt;a href="http://www.alsa-project.org/"&gt;Advanced Linux Sound Architecture&lt;/a&gt; on the server because it has better support for the server&amp;#8217;s built-in audio chip (CS4236B).&lt;/p&gt;


	&lt;p&gt;Playing around for a while, I managed to get decent recordings to &lt;span class="caps"&gt;WAV&lt;/span&gt; format. Since WAVs are rather large (about 200 MB/hr at the settings I was using) I tried re-encoding the recordings as Ogg Vorbis in various bitrates, but ultimately settled on &lt;a href="http://www.speex.org/"&gt;Speex&lt;/a&gt;, which is much better at compressing speech. Final file sizes are about 10 MB/hr, which is fine considering my hard-drive space.&lt;/p&gt;


	&lt;p&gt;Next, I wrote a small shell script to record a show, compress it, and store it in a library:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;#!/bin/bash

# Simple script to record a radio show and save as a Speex-encoded file
# Tom Moertel &amp;lt;tom@moertel.com&amp;gt;
# 20 Feb 2004
#
# Usage: record-show &amp;lt;show-name&amp;gt; &amp;lt;show-duration-in-seconds&amp;gt;

#
# Recordings are saved in the following directory structure:
#
# ~/recordings/&amp;lt;show-name&amp;gt;/2004/02/&amp;lt;show-name&amp;gt;--2004-02-19--Thu--2359.spx
#
# Directories are created as needed.

# Check arguments.

if [ -z "$1" ]; then
    echo 'Usage: record-show show-name show-duration-in-seconds'
    exit 1;
fi

# Set up definitions for use later

show_base="$HOME/recordings" 
show="${1:-recording}" 
duration="${2:-3600}" 
year=$(date +%Y)
month=$(date +%m)
now="$(date +%F--%a--%H%M)" 
showdir="$show_base/$show/$year/$month" 
showfile="$showdir/$show--$now.spx" 

# Make directory to contain the show recording (if necessary)

mkdir -p "$showdir" &amp;gt;&amp;#38;/dev/null

# Record the show and exit with the exit status of speexenc

arecord -q -d $duration -c2 -r16000 -f S16_LE |
  speexenc --vbr --vad --dtx - "$showfile" &amp;gt;&amp;#38;/dev/null
exit $?
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Finally, I programmed my &amp;#8220;Radio &lt;span class="caps"&gt;VCR&lt;/span&gt;&amp;#8221; to record any potentially interesting shows that are broadcast by my local &lt;span class="caps"&gt;NPR&lt;/span&gt; affiliate. This was simple using my script above and the following crontab:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;00 06 * * 1-5           record-show morning-edition         3600
00 12 * * 1-5           record-show day-to-day              3600
00 15 * * 1-5           record-show fresh-air               3600
00 17 * * 1-5,6-7       record-show all-things-considered   3600
30 18 * * 1-5           record-show marketplace             1800

00 08 * *     6-7       record-show weekend-edition         3600
00 10 * *     6         record-show car-talk                3600
00 10 * *       7       record-show studio-360              3600
00 11 * *     6         record-show whad-ya-know            7190
00 13 * *     6         record-show wait-wait-dont-tell-me  3600
00 15 * *       7       record-show this-american-life      3600
00 16 * *       7       record-show splendid-table          3600
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;All in all, this has turned out to be a great hack &amp;#8211; simple, fun, &lt;em&gt;and&lt;/em&gt; useful.&lt;/p&gt;</description>
      <pubDate>Fri, 20 Feb 2004 12:00:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:2a9de8f2d4f2bf5d9a4ff4a40e9f9340</guid>
      <author>Tom Moertel</author>
      <link>http://blog.moertel.com/articles/2004/02/20/my-new-radio-vcr</link>
      <category>hacks</category>
      <trackback:ping>http://blog.moertel.com/articles/trackback/37</trackback:ping>
    </item>
  </channel>
</rss>
