FunWithElectronics.com
          - Collection of Information for those with Electronics as a Hobby
Up one level (Linux command line)

Record system output sound in Linux with pacat (Pulseaudio)

When pulseaudio is used as the sound server of the system, there is a simple way to record the output sound to file on the command line using the pacat-command. This short article describes how to do it.



In order to find the correct device you should run this command:
pacmd list | grep ".monitor"
When you see something like:
	alsa_output.pci-0000_06_05.0.analog-stereo.monitor/#1: Monitor of CA0106 Soundblaster Analog Stereo
and the soundcard corresponds to the one you want to monitor, you know which device name to use. Here it is: alsa_output.pci-0000_06_05.0.analog-stereo.monitor

Afterwards pacat is used to read the signal and sox is used to change the output format. See the man page of sox for parameters to choose for correct output format. The default output from pacat is raw audio, rate 44100, signed-integer, little-endian, 16-bit and stereo. The sox reads from standard input by specifying "-" as filename. The format of the output file is therefore specified after the "-" in the examples under.

Here is an example of how to write to a float formatted raw audio file with mono sound at a rate of 40000sps:
pacat --record -d alsa_output.pci-0000_06_05.0.analog-stereo.monitor | sox -t raw -r 44100 -s -L -b 16 -c 2 - -t raw -r 40000 -f -b 32 -c 1 output.raw
This one is nice if you will record sounds for using in gnuradio. To record to a wav-file with a rate of 44100sps, simply do like this:
pacat --record -d alsa_output.pci-0000_06_05.0.analog-stereo.monitor | sox -t raw -r 44100 -s -L -b 16 -c 2 - "output.wav"



Add a comment:

Fill in number
Name:
Title:
Text:
 
ste - test (2016-07-29 17:48:26)
set
- Adam Di Carlo (2015-11-11 03:24:05)
Your grep is a bit suboptimal, its better like: pacmd list | grep "\.monitor"
works - Lol (2014-04-13 10:52:38)
I have spent some hours with pulseaudio until I've found this article. Thx!
smth like that - anon (2014-04-01 14:07:04)
pacat --record -d alsa_output.pci-0000_01_0a.0.analog-stereo.monitor | sox -t raw -r 44100 -L -e signed-integer -S -b 16 -c 2 - "output.wav"
thanks a lot - xav (2014-01-24 21:21:53)
excellent tip ! Knowing that pulseaudio is now the default sound server on most linux distro, you found the recipe for the best ripper in town ! i'll test that immediatly
muchas gracias cabron - el mas chingano (2012-10-04 19:14:39)
hey dude thanx just what i was searching for, appreciate. big muchas gracias!!! now i gonna kick audacity of my opensuse 12.1


Privacy | Contact