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:
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
August 8, 2006 at 11:14 am |
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.
August 21, 2006 at 9:39 pm |
Great page! I’ve tried so many wird things on the console to achive this with little success. Now I know the easy solution
October 30, 2006 at 8:31 am |
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.
November 29, 2006 at 9:20 am |
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..
December 10, 2006 at 1:56 pm |
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
December 14, 2006 at 11:04 pm |
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 ‘–’
February 2, 2007 at 4:53 am |
‘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.
March 13, 2007 at 11:34 am |
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
May 9, 2007 at 8:35 am |
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.)
May 12, 2007 at 11:24 am |
“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!!
June 22, 2007 at 6:31 pm |
This is the best HOWTO ever. Finally I got my desk- and laptop to record after a lot of tries.
Thank you
July 26, 2007 at 12:14 am |
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!
October 16, 2007 at 10:54 am |
Hi!
How about arecord restriction on size of output file? – it is set to 2GB…
October 29, 2007 at 2:32 pm |
[...] Referencia: Recording audio from the command line [...]
January 1, 2008 at 7:30 pm |
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 ??
January 6, 2008 at 5:40 pm |
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 ?
June 19, 2008 at 11:00 pm |
[...] Referências: http://jordilin.wordpress.com/2006/07/28/howto-recording-audio-from-the-command-line/ [...]
November 23, 2008 at 11:37 am |
This is great. What command should one use to record directly into a flac file?
November 24, 2008 at 9:40 am |
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
April 4, 2009 at 8:17 pm |
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!
April 29, 2009 at 2:17 pm |
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
May 4, 2009 at 6:22 pm |
Well, actually it should be:
arecord -f cd -t raw | lame -x -r – out.mp3
May 5, 2009 at 4:11 am |
eh.. luv it
May 6, 2009 at 12:34 am |
any updates coming ?
June 12, 2009 at 9:56 pm |
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″
July 30, 2009 at 6:43 pm |
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.
July 30, 2009 at 6:56 pm |
Replaced “–” with “-”, recorded silent file ‘out.mp3′
August 13, 2009 at 9:35 pm |
Doesn’t work for me — I can’t seem to find a ‘capture’ mode.
September 8, 2009 at 11:20 pm |
Ditto. I can’t get ‘capture’ to show up.
September 9, 2009 at 3:58 am |
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.