Motivation

I want to capture raw audio from an SDR application to try out some audio processing algorithms on it. It is best done offline on a computer before inserting the algorithm to perform real time. For these experiments, one needs access to data, preferably, real audio stream captured on the air.

Method

If you have pulseaudio or pipewire installed (along with pipewire-pulse for the compatibility layer), then things are pretty easy.

First you need to list all the applications trying to play audio.

pactl list sink-inputs

In the output look for the application.name under the Properties. If the application you are interested is listed, then scroll up and note the ID of the application. Typical output of this application would look like this:

Sink Input #5559
    Driver: PipeWire
    Owner Module: n/a
    Client: 5558
[...]
[...]

In the above example, 5559 is the ID that we mentioned in the previous paragraph.

Now, pulseaudio comes with a "null sink" using which one can create a "monitor" device. To do that do:

pactl load-module module-null-sink sink_name=APPNAME
pactl move-sink-input ID APPNAME

where APPNAME is some string that you can give, say Firefox and the ID is the one we just found above.

Now, to access a monitor device corresponding to this application, use the string APPNAME.monitor. One can use parec(1) to record the audio in a bunch of formats. Check out its manpage.

parec -d APPNAME.monitor --file-format=wav foo.wav

There are other options for parec too like --rate to set a sampling rate etc. One can directly record from a monitor device corresponding to a device.