HOWTO: Recording audio from the command line

July 28, 2006

Recording any sound that goes through your computer is a feature that you don’t have to miss out. Mostly if this sound is music. There are lots of internet streaming mp3 sources that stream audio that you can listen with your computer and why not, you can record to mp3 and have an enormous mp3 library. In this howto I’m going to give you powerful tools to record sound directly to an mp3 file or ogg file from the command line. So, you will be able to record for hours and hours your favourite music without having to worry about your hard disk space.

First of all you have to set up the recording channels by doing

alsamixer

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

alsamixer.png

With the arrow keys select the column Capture and set it to the CAPTUR mode with the space key as in the screenshot. Adjust the recording volume with the arrow keys. You can also set it up with the gnome volume control panel going to the capture tab.

Recording sound to an mp3 file

You’ll need the lame mp3 encoder. Install it by doing

sudo apt-get install lame

Type the following command

arecord -f cd -t raw | lame -x -r – out.mp3

Arecord captures the audio that goes through your computer and pipes it to the lame encoder, so you encode the audio directly to an mp3 file. You can specify more options to the lame encoder such as the bitrate with lame -x -b bitrate. Without specifying the bitrate it encodes to 128kbps constant bit rate cbr. If you want to record for an specific amount of time then:

arecord -f cd -d numberofseconds -t raw | lame -x -r – out.mp3

Recording sound to an ogg file

You’ll need the oggenc (the ogg encoder). Install it by doing

sudo apt-get install vorbis-tools

Type the following command

arecord -f cd -t raw | oggenc – -r -o out.ogg

And you’ll get your sound recorded to an ogg file. Take into account that we record directly to a compressed file, so there’s nothing in between, so you can record for hours saving an incredible amount of hard disk space.

Ripping shoutcast audio streaming

Streamripper allows us to rip audio streaming servers. Install it by typing

sudo apt-get install streamripper

You can connect to any shoutcast radio station with xmms. Once playing get the info and write down the url. Then type:

streamripper url

and you’ll get each song in a separate mp3 file.

Enjoy recording!!! :)
Interesting audio applications.

Audacity-Editing mp3/ogg files

Streamripper-ripping audio streaming servers

Streamtuner-Stream directory browser