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"
时间: 2024-10-25 20:59:39