I'm running Kubuntu 20.04 and what I'm trying to accomplish is to use pulseaudio to mix together a real microphone (Blue Snowball) and a virtual microphone created using pactl like so:
pactl load-module module-pipe-source source_name=virtmic \ file=/home/pyle/dev/virtmic format=s16le rate=16000 channels=1The desired result is to have some kind of virtual recording device which takes input both from the real microphone and from the virtual microphone device. Preferably also while playing back any audio coming from the virtual microphone to the default output device.
I've tried reading the docs and tinkered with sinks but I can't seem to get it working right. I can set the virtual microphone as the default recording device and pipe audio to it but that won't let me use the real microphone at the same time, and I would also like to hear the audio piped to the virtual microphone (but not the audio from the real microphone) played back to the default audio output.
Update 2021-02-03:
Thanks for the help @ChrisAga, it still seems to not quite work though.
I put it all together like this: #!/bin/bash
microphone="alsa_input.usb-Blue_Microphones_Blue_Snowball_2011BAA018H8-00.analog-stereo"
# Setup sink
pactl load-module module-null-sink \ sink_name=mix-for-virtual-mic \ sink_properties=device.description=Mix-for-Virtual-Microphone
# Real microphone to mix-for-virtual-mic
pactl load-module module-loopback \ source=$microphone \ sink=mix-for-virtual-mic latency_msec=20
# Virtual microphone device to pipe stuff to
pactl load-module module-pipe-source \ source_name=virtmic \ file=/home/pyle/dev/virtmic format=s16le rate=16000 channels=1
pactl load-module module-combine-sink \ sink_name=virtual-microphone-and-speakers \ slaves=mix-for-virtual-mic,@DEFAULT_SINK@
pactl load-module module-remap-source \ master=mix-for-virtual-mic.monitor \ source_properties=device.description=mixed-micAfter running this and starting pavucontrol-qt to check my inputs and outputs I have two new items under Recording, Loopback to Mix-for-Virtual-Microphone from Blue Snowball Analog Stereo and Remapped Stream from Monitor-of-Mix-for-Virtual-Microphone. Both seem to only react to actual audio input, not audio piped to the virtual microphone device.
Under Output Devices I have two new devices as well, Mix-for-Virtual-Microphone and Simultaneous output to Mix-for-Virtual-Microphone,Starship/Matisse HD Audio Controller (X570-A PRO motherboard) Analog Stereo. The former appears to only output actual microphone audio.
I also have multiple new input devices but what stands out there is that when I pipe audio to virtmic it seems to only cause a reaction on the Unix FIFO source /home/pyle/dev/virtmic device while real audio from the microphone shows up on Blue Snowball Analog Stereo, mixed-mic and Monitor of Mix-for-Virtual-Microphone.
I've tried fiddling with the settings under Recording and my default output device in the Plasma volume settings but no combination of settings I've tried seems to work though I've noticed that if the only setting I change is the default output device then when I switch back to Headphones I'll hear my microphone (but no the piped audio).
Is there anything I've missed here?
11 Answer
There are several solutions and the tricky part is to get a real source which can be used as a microphone by the applications.
Create a sink and loopback your real microphone to it
pactl load-module module-null-sink \ sink_name=mix-for-virtual-mic \ sink_properties=device.description=Mix-for-Virtual-Microphone
pactl load-module module-loopback \ source=<your real pulse audio source here> \ sink=mix-for-virtual-mic latency_msec=20Create your virtual mic and send it's stream to the "mix" sink and the default audio output
pactl load-module module-pipe-source \ source_name=virtmic \ file=/home/pyle/dev/virtmic format=s16le rate=16000 channels=1
pactl load-module module-combine-sink \ sink_name=virtual-microphone-and-speakers \ slaves=mix-for-virtual-mic,@DEFAULT_SINK@Remap the monitor of of the "mix" as a pulse audio source that apps will use as a microphone
pactl load-module module-remap-source \ master=mix-for-virtual-mic.monitor \ source_properties=device.description=mixed-micYou adjust the relative level of your virtual mic by ajusting the output volume of the combine think which should be listed as "Simultaneous output to …"
1