Published on July 21, 2017; tags: Linux
This article explains how to record an audio stream on a Linux system running PulseAudio.
You can record both input streams (microphones) and output streams (whatever you are hearing in your headphones). However, each stream goes to a separate file. If you want to record, say, a Skype conversation, record both streams and merge them afterwards in audacity.
First, find out the PulseAudio name of the stream you want to record.
If you want to record a microphone, run
pacmd list-sources | egrep '^\s+name: .*alsa_input'
Here is my output:
name: <alsa_input.pci-0000_00_1f.3.analog-stereo> name: <alsa_input.usb-Audio-Technica_ATR_USB_microphone-00.analog-stereo> name: <alsa_input.usb-Focusrite_Scarlett_Solo_USB-00.analog-stereo>
In the above output,
alsa_input.pci-0000_00_1f.3.analog-stereois the laptop’s built-in microphone,
alsa_input.usb-Audio-Technica_ATR_USB_microphone-00.analog-stereois an Audio Technica USB microphone, and
alsa_input.usb-Focusrite_Scarlett_Solo_USB-00.analog-stereois a Focusrite USB audio interface.
If you want to record an output (e.g. the person talking to you on Skype), similarly run
pacmd list-sources | egrep '^\s+name:.*\.monitor'
Once you know the name of the stream you want to record, run
parecord --channels=1 -d STREAM_NAME filename.wav
For instance, if I wanted to record the XLR microphone plugged into the Focusrite Scarlett Solo interface, I would run
parecord --channels=1 -d alsa_input.usb-Focusrite_Scarlett_Solo_USB-00.analog-stereo filename.wav
When you are done recording, terminate the process by pressing
--channels=1 forces your recording to mono, which is usually what you want.
The recording is not compressed, so make sure you have enough disk space. Assuming the standard sample rate (44kHz) and sample size (16 bit), you will need 320 MB per hour of recording.
Reddit user dbrass asks:
is it possible to record sounds from specific applications instead of everything that goes out to my headphones? That way, it would be possible to easily remove any system or notification sounds.
Yes, it is!
At a high level, here is what you are going to do:
recordingsink. Otherwise, you will be able to record a stream but not hear it yourself. So, let’s call this sink
recordingsink to a file.
Find out the name of your output device by running
pacmd list-sinks | egrep '^\s+name: .*alsa_output'
In my case, it says
To create the two sinks, run these commands (you need to substitute the name of the output device that you learned on the previous step):
pacmd load-module module-null-sink sink_name=recording sink_properties=device.description=recording pacmd load-module module-combine-sink sink_name=combined sink_properties=device.description=combined \ slaves=recording,alsa_output.pci-0000_00_1f.3.analog-stereo
If you do this often, make it a permanent setup by creating the file
~/.config/pulse/default.pa with this contents (note that the long
load-module command should be on a single line, don’t wrap it):
.include /etc/pulse/default.pa load-module module-null-sink sink_name=recording sink_properties=device.description=recording load-module module-combine-sink sink_name=combined sink_properties=device.description=combined slaves=recording,alsa_output.pci-0000_00_1f.3.analog-stereo
Now, redirect the sound to the
pavucontrolcommand (a graphical window will appear) and go to the “Playback” tab.
pavucontrol. If it doesn’t, make sure the application produces some sound. Unfortunately, until the application tries to play something, PulseAudio cannot “see” it.
combinedsink for the application as shown on the screenshot:
Finally, record the
recording stream’s monitor as explained above:
parecord --channels=1 -d recording.monitor filename.wav