Record streaming audio

In this article we will discuss how you can record direct into your prefered hard drive any streaming audio resource. Quiet fancy, don't you think? :)
First of all ensure that you have sox installed, just type apt-get install sox.

Open an editor and paste the following code:

if [ -z "$WAV" ]; then
echo "Usage: $0 outputFile.wav" >&2
exit 1
rm -f "$WAV"

# Get sink monitor:
MONITOR=$(pactl list | grep -A2 '^Source #' | \
grep 'Name: .*\.monitor$' | awk '{print $NF}' | tail -n1)

# Record it raw, and convert to a wav
echo "Recording to $WAV ..."
echo "Ctrl-C or Close this window to stop"
parec -d "$MONITOR" | sox -t raw -r 44100 -sLb 16 -c 2 - "$WAV"

then make file executable. Assuming the file name is type:
chmod +x
and then open a browser with any radio station. As long as you start listening the radio type into the terminal:
./ myradio1.wav

You will get a screen like the following:
$ ./ rockfm1.wav
Recording to rockfm1.wav ...
Ctrl-C or Close this window to stop

If you make an ls -lh to the output folder you will see the size growing. That's it, you just started recording audio direct to your hard drive.

Posted on: 17/01/2011

Penny, posted on 14/10/10 19:21:09
You can encode direct to mp3 using the following command into your script: parec -d "$MONITOR" | sox -t raw -r 44100 -sLb 16 -c 2 - -t wav -| lame - "$TIME".mp3