How to Record Streaming Radio in Linux

How to Record Streaming Radio in Linux

Step 1:

First setup the Ubuntu Box (desktop edition).

Step 2:

Write a bash script to open the website:

#!/bin/bash
export DISPLAY=:0
xdg-open https://freespeech.org/watch-live

Step 3:

Setup alsamixer

Type in command line:

alsamixer

Once there, select the capture view by typing the tab key. You’ll get the next screen:

Recording sound to an mp3 file

You’ll need the lame mp3 encoder. Install in next step

Step 4:

Install Lame

sudo apt-get install lame

Step 5:

Setup arecord to record the incoming stream. For my example, I will use 90 seconds as a test. More about arecord at their website.

**I have setup a MillerRecordings folder on the desktop.

arecord -f dat -d 90 -D hw:0,0 /home/user**/Desktop/MillerRecordings/miller-`date +%Y%m%d`.wav

This will end firefox once the recording is over after 90 seconds:
killall firefox

For the format (f) I am using dat. Duration (time) is 90 seconds (for 1 hour, this will be 3,600 (60 minutes x 60 seconds).  The file will be in wav format and the name will be miller-date.wav.

Step 6:

Next Step is to covert the recording into MP3 so I can move it to the server:

for f in /home/user**/Desktop/*.wav ; do lame -VO -h -b 64 –lowpass 15 -a –resample 16 –vbr-new $f ; done

Next, if needed, move the original wave file to backup folder:
mv /home/user**/Desktop/MillerRecordings/*.wav /home/user**/Desktop/backup

Step 7:

Now we will copy the completed mp3 file to the music servicer:

cd /home/user**/Desktop
ftp -n ftp.test.net <<END
user music@test.net password
put *.mp3
quit
END

Here is a completed sample (bash script):

#!/bin/bash
export DISPLAY=:0
xdg-open “https://freespeech.org/watch-live” + “autoplay=1” | arecord -f dat -d 90 -D hw:0,0 /home/user**/Desktop/miller-`date +%Y%m%d`.wav

killall firefox

for f in /home/user**/Desktop/*.wav ; do lame -VO -h -b 64 –lowpass 15 -a –r$

mv /home/user**/Desktop/*.wav /home/user**/Desktop/backup

cd /home/user**/Desktop
ftp -n ftp.test.net <<END
user music@test.net password
put *.mp3
quit
END