HOWTO: Recording audio from the command line

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

30 Responses to “HOWTO: Recording audio from the command line”

  1. Maurice Says:

    I’ve been trying to do this for ages. You may have concluded thet I’m not too computer savvy so thanks for the help – it works.

  2. Sven Says:

    Great page! I’ve tried so many wird things on the console to achive this with little success. Now I know the easy solution :)

  3. Matt Says:

    Thanks for this howto. Now I can record my favourite radio programs and copy them to my portable mp3 player. Next step is to set up some cron jobs.

  4. Asif Ali Rizwaan Says:

    thank you friend, i really appreciate the small tutorial for recording sound in linux.. and encoding into mp3 and encode into .ogg format.

    thanks. i like it..

  5. Phil Sammons Says:

    Thankyou sooo much.

    Been hacking away trying to get arecord to work for ages, so i’m glad that now works. But streamripper works soo much bettter anyway, so now I use that.

    Thanks

    Phil

  6. Asif Ali Rizwaan Says:

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

    should be

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

    the ‘-’ is converted to special character ‘–’

  7. Dan Farrell Says:

    ‘LINE IN’ CAPTURE

    The capture screen in alsa mixer often allows for the selection of one of a multiple set of inputs. on my system, the default was Mic, but pressing ’spacebar’ when ‘Line In’ was selected make that the capture device.

  8. mrdevis Says:

    Great, and nearly just what I’m looking for. One small but, as I need to record VERY long files, is there: a) a file size limit in linux for mp3 coded files? And if so: b) a way to make seamless chunks of mp3 files at max size?

    Thanks, Jeroen

  9. Erik Christiansen Says:

    Many thanks for this method. Next step is to find out how to use the -D option to obviate the need for manual mucking with alsamixer. Then the whole deal could be scripted. The arecord manpage makes selection of front microphone a complete mystery. (arecord -L doesn’t help much either, sadly.)

  10. vpv Says:

    “With the arrow keys select the column Capture and set it to the CAPTUR mode with the space key as in the screenshot.”

    God bless you, man! You saved my life!!

  11. max Says:

    This is the best HOWTO ever. Finally I got my desk- and laptop to record after a lot of tries.
    Thank you

  12. Donneker Says:

    Hi, just wanna say, you can use radio_rip also for ripping (radio-) streams. Its good to use with streamtuner. Just look at my project page under http://www.donneker.de/projects/radio-rip/
    You dont have to type the URLs any more, click and hear & record with just easy streamtuner usage. It also splits the songs after the stream titles. enjoy!

  13. GByte Says:

    Hi!

    How about arecord restriction on size of output file? – it is set to 2GB…

  14. Odaiba Net » Blog Archive » Odaiba Net 38 Says:

    [...] Referencia: Recording audio from the command line [...]

  15. Charles Says:

    Tried all above and everything seemed to go ok.
    The out.mp3 file is generated but it is silent when played back. the file size is not zero.

    Any suggestions ??

  16. Alok Says:

    I have an in-built mic and an external mic jack (though no mic is connected to it). When I tried to record sound, all I got was an empty (44byte) wave file. I am not sure what is going wrong…. In fact I have two capture columns in my mixer (which I daresay correspond to the two mic inputs) I have checked both of them to ensure both are used to capture sound. Does anyone know what is going wrong here ?

  17. Enfim o capitulo « btux Says:

    [...] Referências: http://jordilin.wordpress.com/2006/07/28/howto-recording-audio-from-the-command-line/ [...]

  18. Bill Says:

    This is great. What command should one use to record directly into a flac file?

  19. Bill Says:

    To record in flac it is essential to use arecord to create wav not raw output. So command is:

    arecord -f cd -t wav | flac – -o /home/Bill/Music/out.flac

  20. yo yo Says:

    If you get empty, silent files using this method, you might need to also enable the “Mix” capture channel in alsamixer. That did the trick for me.

    Thank you for the excellent tutorial!

  21. Ben Says:

    pardon my ignorance…

    LAME 32bits version 3.98.2
    arecord: version 1.0.16

    arecord -f cd -t raw | lame -x – out.mp3
    Recording raw data ’stdin’ : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
    Warning: unsupported audio format

  22. jordilin Says:

    Well, actually it should be:

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

  23. MalBoakly Says:

    eh.. luv it

  24. MalBoakly Says:

    any updates coming ?

  25. meho_r Says:

    Hi. I managed to record a sound, but it contains terrible noise (I can here a song I’ve been recording through it). Any ideas? And, BTW, that “–” doesn’t work for me. I had to put “-” before “out.mp3″

  26. Raffles10 Says:

    Doesn’t work:

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

    results in:

    Could not find “–”.
    Recording raw data ’stdin’ : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

    Nothing is recorded.

  27. Raffles10 Says:

    Replaced “–” with “-”, recorded silent file ‘out.mp3′

  28. tensigh Says:

    Doesn’t work for me — I can’t seem to find a ‘capture’ mode.

  29. Jo Says:

    Ditto. I can’t get ‘capture’ to show up.

  30. tensigh Says:

    Jo,

    I think it has to do with how Ubuntu uses a sound server like thing. I managed to do what I needed but not by using this method.

    There’s a way to set your default recording input to use ‘monitor’ which is basically your sound card. And if you think about it, it’s the same as a band using a monitor on a stage for hearing how they’re playing. This seems to work and I can record now any sound that comes out of my sound card.

Leave a Reply