To record sound we will be using a program called sox. The name sox comes from SOund eXchange and the man page describes it as a "universal sound sample translator". It will basically convert sounds from almost any format, bitrate, number of channels, sampling rate, etc. to another other (...,..). With the flexibility of a Unix-like environment behind it, you can use a device like "/dev/dsp" as the the input file (or output file for that matter) instead of something like a wave file. Let's look at an example.
rec -c2 -r44100 -twav -sw test1.wav
The "rec" command is a small wrapper around sox which just uses the first soundcard (or whichever one you specify) as input instead of looking for a regular file path. In this example we use -c2 to tell it to record both channels (left and right), -r44100 to tell it to use a sampling rate of 44100 samples per second (the sampling rate of CD quality sound), -twav to tell it to output the wav file format the Window$ made so popular and -sw to tell it to use a word sized sample width.
We can put the recorded sound directly out to the soundcard using the following command. We use "-" to tell the commands to read from standard input or output (whichever one they are expecting)
rec -c2 -r44100 -twav -sw - | play -
Now we will do something a little more advanced by encoding this audio on-the-fly and saving it directly to an mp3 file on our disk. This keeps us from having to take up a lot of our disk space during recording just to delete the huge file when we are finished encoding.
rec -c 2 -r 44100 -t wav -s w - | lame -h -b128 - a.mp3
With this command we record the same way that we have been doing it, but now we pipe our output directly into the lame mp3 encoder, then we tell lame to save it's encoded output to the file a.mp3.
![[logo]](logo.png)