[pulseaudio-discuss] How to combine microphone audio and music from application to pipe to video conference

Sean Greenslade sean at seangreenslade.com
Sat May 16 05:23:11 UTC 2020


On Fri, May 15, 2020 at 11:04:00PM -0400, Samir Parikh wrote:
> Hello,
> 
> I am trying to combine the audio from my microphone (either built in
> microphone from my laptop or bluetooth headset) with music playing
> from Rhythmbox Music Player running on Ubuntu 16.04 and pipe that as
> the audio input to video conference services such as Jitsi.
> 
> I don't know much about Linux audio internals and wasn't sure how to
> do this.  Can I do this completely via the operating system using
> Pulse Audio?  Do I need to do something with Jack?  Or do I need
> specialized software such as OBS, Ardour or Reaper?
> 
> Any help or suggestions on pointing me in the right direction or how
> to get started would be greatly appreciated.  I'm hoping that I can do
> this completely through software without external hardware such as a
> mixer or something.

This is definitely possible entirely within pulseaudio. I'll go over the
basic concepts here, then show an example.

Pulse has two types of sound devices, sources and sinks. Sources are
input devices like microphones. Sinks are output devices like speaker or
headphone ports. Programs that work with sound can attach to sources in
order to pull sound in, and can attach to sinks to output sound. I
suggest playing around with the "pavucontrol" utility to see what
sources and sinks are present on your machine. It also shows what
applications are recording or playing back audio, and allows you to
redirect existing audio streams on the fly. It's quite handy.

Within pavucontrol, there is a separation between sources and sinks, and
the two cannot directly be mixed. In order to mix a music sink and a
microphone source, we'll use a few manually-loaded pulseaduio modules.
Note that this can easily be scripted once you find the set of commands
that work well for your setup.

We'll first need to create a "virtual mixer" device. This will receive
both the music and the voice streams and mix them together. Run the
following commands:

$ pacmd load-module module-null-sink sink_name=virt_mix
$ pacmd update-sink-proplist virt_mix device.description=VirtualMixer

Pavucontrol should now list "VirtualMixer" in the Output Devices tab.

Next, you'll need a loopback device to feed your microphone's sound to
this virtual mixer. Run this command:

$ pacmd load-module module-loopback sink=virt_mix

In pavucontrol, go to the Recording tab and change the Show dropdown to
All Streams. There should be an entry titled "Loopback to VirtualMixer"
with a dropdown to select the loop input. Pick the appropriate input
that corresponds to your microphone.

Now you can begin playing music, and in the Playback tab of pavucontrol
move the music playback to the VirtualMixer.

Finally, begin recording / using your conferenece application. In the
Recording tab of pavucontrol, find the entry for the recording
application / conference application. Change its microphone to "Monitor
of Null Output", which is the virtual source that pulls from the
virt_mix sink. Verify that it is behaving the way you want.

Hopefully this isn't too confusing. Feel free to ask for clarification
if needed. I've set up a number of complex audio workflows in linux,
some of which took a lot of experimentation to get working well.

--Sean



More information about the pulseaudio-discuss mailing list