Forwarding Desktop Audio Into Your Microphone Output on Linux
Created: March 1st, 2021 19:13
Updated: March 1st, 2021 19:40
Eyes laid on this: 51
If you use PulseAudio it is possible using their Sink/Source system to merge a desktop programs audio with your microphone and then use that for a VoIP call.
To use my method described below you will need to have the program "Pavucontrol" installed from your choice of package manager.
Setting up the Script
Here is the script you will want to use. The only lines you need to change are the "SPEAKERS" and "MICROPHONE" lines at the start of the script.
#!/bin/bash SPEAKERS="your speaker name here" MICROPHONE="your mic name here" #virtual1=fSource gets the audio source your want to forward and listen to(browser, media player, etc) #result gets fSource + mic and it gets sent to your voip software(discord, etc) pactl load-module module-null-sink sink_name=fSource sink_properties=device.description="fSource" pactl load-module module-null-sink sink_name=result sink_properties=device.description="result" pactl load-module module-loopback source=fSource.monitor sink=$SPEAKERS pactl load-module module-loopback source=fSource.monitor sink=result pactl load-module module-loopback source=$MICROPHONE sink=result
To determine what your Speaker and Microphone names according to PulseAudio, you need to run the following commands to probe PulseAudio:
pacmd list-sources | grep name:
pacmd list-sinks | grep name:
Here is a sample output of what I get from running the second command:
name: <alsa_output.pci-0000_00_00.0.hdmi-stereo> name: <alsa_output.usb-DisplayLink_USB3.0_5K_Graphic_Docking_1234123412341-00.analog-stereo> name: <alsa_output.pci-0000_00_00.0.analog-stereo>
From this list I use bluetooth headphones so I would pick the last one, entering it without the
<> characters like so:
Once you have updated both the SPEAKERS and MICROPHONE in your script then is set up and ready. You can now run the script and move onto the next step. Just save the script in a file named something like "forwardSound.sh" and then run it in a terminal from the directory where you saved this script like so:
when you run the script it should output a few numbers without errors similar to this(it wont necessarily be the same numbers):
29 30 31 32 33
If so then it worked.
Setting up the Sinks and Sources with Pavucontrol
We use this program to change what sounds we would like to forward, and to make sure that the VoIP software can hear the forwarded sounds. Although it is should be possible to change this using command line, I find this is one of those cases where the GUI way is easier to do it on the fly. The 2 important tabs in this program we will be using is the "Playback" and "Recording" tabs.
The part that should be automatically set up
This part that I will explain should be automatically set up when you run the script. However I will still write it out incase if you have issues.
In Pavucontrol under the recording tab you should have 3 new sources. One of them should be
Loopback to [your speakers] from
[your speakers] is whatever speaker device you chose earlier. On the right hand side the setting should be set to "Monitor of fSource". If it is not change it to that now.
The other 2 new sources should be called:
Loopback to result from
The first one should be set to "Monitor of fSource" and the second one set to whatever microphone you set earlier. If they aren't then change that now.
You need to also make sure that none of these sources are muted, the right side where the speaker icon is should not be checked off/selected. I found that sometimes PulseAudio will default to starting these as muted.
The part you need to manually set up
Selecting the program that you wish to forward the sound, as well as the microphone your VoIP program uses needs to be manually selected.
First go to the playback tab. This is where your programs that are playing audio reside. If you cannot see your program then usually all it takes is just to start playing audio from that program and it should appear.
For a given program that you wish to forward the sound of, just change the target on the right side to be "fSource" rather then what it is set to by default(usually just your speakers).
Next go to the Recording tab. Whenever you join a VoIP call a new sink should appear. For Discord this is usually called something like "WEBRTC VoiceEngine: recStream from". On the right side you need to change the setting from your default(usually your microphone) to be "Monitor of result"
Now your audio from any program you wish is forwarded to your VoIP call. Enjoy :^)
Note 1: Some VoIP automatically detect if you are talking to turn on the mic. This can cause the audio you forward to cut in/out. If this happens either bump up the input sensitivity so it can more easily auto turn on the mic, or simply use push to talk.
Note 2: Some VoIP programs will default to playing sound out of your most recently plugged in "sink" rather then to your actual speakers. I have noticed discord to do this at least once where it defaulted to playing audio to "result" and thus I wouldn't be able to hear anything. Just change it manually in the settings of the VoIP program to use your speakers.
Note 3: Restarting your PC will set PulseAudio back to before you did any of the above. So when restarting you would have to rerun the above script to forward your sound again. If you don't want to forward your sound anymore after running the script just change the outputs in Pavucontrol or restart your PC.
Back to Index