36

I need to create a virtual output in PulseAudio so as to be able to capture and stream audio from a specific source.

I know that it's possible to re-route a specific application's output to a given output device like so, using pavucontrol:

enter image description here

I'm looking to add another virtual output to the "Output Devices": enter image description here

Is this possible, and if so, how can I do it?

5 Answers 5

38

You can add a sink with

pacmd load-module module-null-sink sink_name=MySink
pacmd update-sink-proplist MySink device.description=MySink

You can add a loopback device with the command

pacmd load-module module-loopback sink=MySink
6
  • 2
    For input it appears there is a pacmd load-module module-null-source as well, though it has an input level reading that spikes around. Feb 20, 2018 at 23:06
  • 1
    using the pacakges "paprefs" makes configuring the sink pretty straightforward. Only need to enable simultaneous outputs
    – joshpetit
    Dec 31, 2020 at 0:09
  • and here's how to remove the sink this answer adds: unix.stackexchange.com/questions/263263/… Mar 29, 2021 at 21:21
  • You may also want to consider pacmd update-source-proplist MySink.monitor device.description='"Monitor of MySink"'
    – NthPortal
    Dec 17, 2021 at 3:00
  • How do I forward the output of the null sink to a physical output device, so I can hear it? The loopback module just forwards an input to that, not forwards it to an output.
    – mekb
    Aug 31, 2022 at 11:49
15
sudo modprobe snd_aloop

Adds a loopback device to ALSA, which appears in the PulseAudio Volume Control. Redirect your stream there, and presto!

Not sure how to add multiple loopback devices.

1
  • on Archlinux / Manjaro Linux I think it is sudo modprobe snd-aloop with an hyphen instead of an underline Jun 18, 2022 at 15:21
11

A little complement to @mxc's answer, as he said you can use the module-null-sink as a virtual output with:

    pacmd load-module module-null-sink sink_name=MySink

This creates a new sink ("virtual output") that you can use for your application. For every sink you create, pulseaudio will also create a monitor source, so in addition to your MySink output device, you will have a MySink.monitor input device that you can use to capture what is sent to your virtual output.

This way it is easy to capture, restream or record the audio an application outputs.

This is a pure Pulseaudio solution and doesn't require Alsa, so it will also work with a different backend than Alsa for Pulseaudio.

7

Besides creating the sink, most applications filter out monitor sources. To be able to pick the source directly for example in Google Meet, the module-remap-source helps.

# create sink
pactl load-module module-null-sink sink_name=virtmic \
    sink_properties=device.description=Virtual_Microphone_Sink
# remap the monitor to a new source
pactl load-module module-remap-source \
    master=virtmic.monitor source_name=virtmic \
    source_properties=device.description=Virtual_Microphone

(found this from https://aweirdimagination.net/2020/07/19/virtual-microphone-using-gstreamer-and-pulseaudio/)

Another possibility is to create a file ~/.config/pulse/default.pa with content:

.include /etc/pulse/default.pa

load-module module-null-sink sink_name=virtmic sink_properties=device.description=Virtual_Microphone_Sink
load-module module-remap-source master=virtmic.monitor source_name=virtmic source_properties=device.description=Virtual_Microphone

run pulseaudio -k to reload the configuration

You can use pavucontrol to route the audio from any application (like Spotify) to the virtual microphone sink.

5

I never could get snd_aloop to work on my systems. Furthermore using ffmpeg -f pulse -i alsa_output.pci-0000_00_1f.3.analog-stereo.monitor etc. caused there to be a 1-2 second lag in the system audio recording. The answer by mxc helped me to find my solution, but I wanted to add a little bit of information.

I first needed to set my Pulse Monitor of Built-in Audio to default. Then I ran the commands listed above. I wanted this to be the default on my profile every time so I created ~/.config/pulse/default.pa and added the following lines:

.include /etc/pulse/default.pa

set-default-source alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
load-module module-null-sink sink_name=MySink
update-sink-proplist MySink device.description=MySink
load-module module-loopback sink=MySink

The first line includes the system-wide PulseAudio settings. Then the last four lines are prioritized for the user over any system settings. Of course any of the last four lines can be run in the terminal when preceded by pacmd.

To get the name of your Pulse Monitor of Built-in Audio device run:

pacmd list-sources | awk '/index:/ {print $0}; /name:/ {print $0}; /device\.description/ {print $0}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .