Schedule Streaming Audio Recordings in Ubuntu

Schedule Streaming Audio Recordings in Ubuntu
If you're like me, your bosses actually expect you to work while on the job, and not sit listening to your favorite radio show like you might want to. In this instructable, I'll show how to record any audio stream automatically using mplayer, lame and cron to schedule the job.
 
Remove these adsRemove these ads by Signing Up
 

Step 1Get Ubuntu, create directories

Get Ubuntu, create directories
For this instructable, you'll need to have Ubuntu Linux. I run 7.04, but this may work for other versions as well. If people seem interested, I'll write a seperate instructable up showing how to do this with Windows.

If you already run Ubuntu, the only things you need are freely available through apt. Use the following commands at a terminal to install Lame, Mplayer and KCron.

sudo apt-get install lame mplayer kcron

Type in your password and confirm the installs.

Use the following commands to create the folders you'll need.

sudo mkdir /scripts

mkdir /home/username/Music/NameOfShow

And this command to take ownership of the directory you just created:

sudo chown YourUserName /scripts
« Previous StepDownload PDFView All StepsNext Step »
20 comments
Jul 30, 2008. 12:11 PMMSpirit says:
Another way is to use the "endpos" option of mplayer instead of pkill script, i.e.
mplayer "mms://rx-wes-sea20.rbn.com/farm/pull/tx-rbn-sea34:1259/wmtencoder/cspan/cspan/wmlive/cspan4db.asf" -ao pcm:file=/tmp/mystream.wav -vc dummy -vo null -endpos "01:00:00";

This would record for 1 hour and stop. A bit cleaner than using kill, plus one less line in crontab.
Aug 24, 2011. 6:22 PMjulietmoss2011 says:
How about recording streaming audio with sound recorder? Perhaps somone will guess this will be illegal. I mean yes it might be if you record streaming audio for the sole purpose of spreading the recordings everywhere on the internet. As long as you do not spread it in any illegal form, it will be a hand way to help you out.

Dec 27, 2008. 12:33 PMNimoTh says:
I tried and googled. endpos doesn't work with -dumpstream. You have to revert to kill using the pid.
Jan 6, 2010. 2:05 PMmatthewbeckler says:
I've had good luck with something like this:

mplayer $STREAM -endpos $DURATION -vo null -ao pcm:waveheader:file=$FILENAME.wav

Where $DURATION is of the form "1:30:00"

More details:
http://www.mbeckler.org/scripts.php#savestream
Apr 13, 2011. 4:53 AMffsman says:
Does mPlayer have to use the speakers when it is recording these shows? Or can it run silently as long as the computer is on? This is crucial since I intend to sneak it into a box I'm building for Grandma so I don't have to have a dedicated box for this.


For background, I'm thinking about setting up a an Ubuntu box just so I can do this. I would set it up to record NPR and another show I like, then save the OGG file to my Ubuntu One account so I can access it from abroad really easily (I'm going on a big trip).
Dec 26, 2008. 5:22 AMveryniceworld says:
I did the same thing recently before I got chance to read your text. The first tool I used was VLC which can do similar thing as mplayer. Same as mplayer, I have to create a cron job to kill the VLC in order to end the recording.

Now, I have changed to use the tool mimms. It works great for me. Since mimms has the option to specify the length of recording in mintue. No need to have 2 cron jobs for each recording anymore.

- Mac
Nov 21, 2008. 9:58 AMbdbull says:
I'm using this to record a 4.5 hour talk radio show from a radio station's internet stream. However, for some reason it's not getting the whole show. So far of 5 recordings this week, none of them recorded the entire show and they are all different file lengths.
Jan 15, 2008. 7:58 PMminchina says:
Thanks for the howto. I had the same problem as frenchie, but resolved it a little bit differently. I added the -msglevel all=-1 command just after my URL. I did this mainly because did not quite understand how his fix worked and could not get it to work. That was a success, but it started another problem. Kcron starts the recording well, and it starts the pkill well, but for some reason the .wav (which is long) only gets converted to a 1 second .mp3. Any tips?

thanks
Nov 21, 2007. 5:41 AMfrenchie says:
Hi, really useful tutorial, thanks a lot. I'm having a strange problem with it though. The script to record the stream runs fine when I run it from the command line, but if I try to run it automatically from the crontab, mplayer crashes every time! MPlayer interrupted by signal 13 in module: play_audio - MPlayer crashed. This shouldn't happen. The script is identical, permissions are the same, I don't understand!! Thanks, John.
Nov 21, 2007. 8:04 AMfrenchie says:
Managed to track down the problem. Yes, I'm using crontab -e to edit the crontab (originally tried kcron and it didn't work there either). My crontab entry originally looked something like this:

03 00 * * 2-6 script URL filename

I edited it to redirect output/error messages like so:

03 00 * * 2-6 script URL filename > $HOME/logfile 2>&1

Now it works just fine! By the way, there's some useful info here that I've used together with your how-to in order to record directly to ogg/mp3 without creating a temporary wav file: http://www.tomtaylor.co.uk/blog/2007/04/17/play-it-again/

Thanks again, it's so cool to be able to record streams automatically.
John.
Nov 21, 2007. 10:37 AMfrenchie says:
You may have already tried this, but if your mp3 player doesn't support ogg natively, maybe this could help: Rockbox. It's an open-source alternative to the factory firmware, and it supports several models of mp3 player. Anyway, the lame conversion works just fine too.

Looking forward to listening to the radio show tomorrow that will be recorded while I snooze tonight!

all the best,
john.
Nov 6, 2007. 8:04 PMTESTING EMAIL VALIDATION says:
This Recorder is better and also lets you schedule your recordings as well as record in mp3s for your ipods. *smile*
http://www.xaudiotools.com/
Sep 23, 2007. 5:17 PMwikityler says:
Wow, this works great. I tried this once with XMMS, to no avail. The only problem is the enormous size of the wave file created. A 4 hour program is over 1.9Gbytes, at 33Kbps! Is there a way to have mplayer record into mp3 or ogg in real time?

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
29
Followers
10
Author:stuffman