20

I am able to play sound through two or more outputs/devices using paprefs and adding a virtual output device, as described in this answer: Play sound through two or more outputs/devices

Now I would like to be able to do the same for the input, so basically to collect the sound input from any of the capable devices available and route it, for example, Skype or Slack. It will be very useful for me in large conference rooms, so that I can distribute multiple speaker/mics around in order to have a good sound quality both ways.

Can anybody suggest a solution?

2
  • 1
    It might be possible in software, but maybe it's also a possibility to look at a pro-level hardware audio mixer (something like this) ? Connect multiple mics to it, and take the output from that to the computer.
    – JonasCz
    Jan 6, 2017 at 19:05
  • I hear you, but it's quite expensive, we already have few bluetooth speakerphones, and the software definitely can do that. You just need to open the pulseaudio volume control, select input devices, you can immediately see that all the microphones are on and are receiving. Thanks for the suggestion tough! Jan 9, 2017 at 10:45

2 Answers 2

28

so basically I figured this out myself after a lot of digging on the internet. This is the best answer I found, in another forum, at http://www.pclinuxos.com/forum/index.php/topic,119695.msg905379.html#msg905379

Basically, you will need first to add a fake channel, a "null sink", where the inputs will be collected. We will call it "inputs" and we will create it using this command:

pactl load-module module-null-sink sink_name=inputs

After that, you will need to create as many virtual channels you need for the devices you need to connect, linking that to the "inputs" channel you created before. So please repeat this command for any input you want to mix (and add one if you want to mix also the input of your laptop):

pactl load-module module-loopback sink=inputs latency_msec=1

(If you find the audio stutters, try increasing the latency)

Now you will have to connect this new "loopback" channels to the device you intend to record from. You can do this using "pavucontrol" (install it if missing), open the "Recording" tab, select "Virtual Streams" from the bottom selector and then make sure you connect a different input to each different loopback.

At this point it's just a matter of using your input in your application for recording, and you're all set! Please remember to setup also the output as described in my original question :)

I am happy to receive any better answer too, as this procedure (even if it can be automated) it's still too much error prone and does not automatically includes new devices added later (you will have to setup a new channel and add them again).

4
  • 8
    "So please repeat this command for any input you want to mix". Would you please provide an example how to change the command for other inputs?
    – Mark
    May 24, 2020 at 10:30
  • Ex. you have 3 microphones. Load pactl load-module module-loopback sink=inputs 3 times. Open pavucontrol and do the following in the gui. Go to Recording tab. You will see three Loopback to Null output devices. Connect each loopback to a different microphone (ie. connect all microphones to Null output). Then set all recording programs to take input from Monitor of Null Output. Then go to Input Devices tab and set Null output as the default device.
    – KamilCuk
    Apr 15, 2021 at 9:47
  • While this did work, I had very high latency issues, like "big stadium" echo. This page: juho.tykkala.fi/Pulseaudio-and-latency showed a parameter for the loopbacks which completely resolved that issue for me. On slower systems, it might cause stuttering. pactl load-module module-loopback sink=inputs latency_msec=1 Mar 28 at 2:06
5

Complementing Bruno Bossola answer, the pactl load-module module-loopback accepts another parameter which is source, which can be helpful if we want to automate the process with a single bash script (i.e. avoid the use of pavucontrol GUI everytime).

we can get the name with the following command:

pacmd list-sources | egrep '(^\s+name: .*)|(^\s+device.description = .*)'
output example:
$ pacmd list-sources | egrep '(^\s+name: .*)|(^\s+device.description = .*)'
        name: <alsa_input.hw_0_0>
                device.description = "Built-in Audio"
        name: <alsa_input.usb-046d_C922_Pro_Stream_Webcam_4B17D4DF-02.analog-stereo>
                device.description = "C922 Pro Stream Webcam Analog Stereo"
        name: <alsa_output.pci-0000_00_1f.3.analog-stereo.monitor>
                device.description = "Monitor of Built-in Audio Analog Stereo"
        name: <alsa_input.pci-0000_00_1f.3.analog-stereo>
                device.description = "Built-in Audio Analog Stereo"

lets say we want to combine Monitor of Built-in Audio Analog Stereo (computer audio) with C922 Pro Stream Webcam Analog Stereo (webcam microphone), then our script will be as follows:

#!/bin/bash

if [ "$1" == "-u" ]; then
  pactl unload-module module-loopback
  pactl unload-module module-null-sink
else
  pactl load-module module-null-sink sink_name=combined sink_properties=device.description="NewInputName"
  pactl load-module module-loopback source=alsa_input.usb-046d_C922_Pro_Stream_Webcam_4B17D4DF-02.analog-stereo sink=combined 
  pactl load-module module-loopback source=alsa_output.pci-0000_00_1f.3.analog-stereo.monitor sink=combined
fi

pacmd set-default-source combined.monitor #Set it as default

Basically if -u option is sent when calling the script it will unload everything, otherwise, it will create the null sink and combine the microphone with computer audio into it.

3
  • This is excellent, thank you! Is there a way to specify the output, and so avoid going to the "Playback" tab and changing "Null-output" to the audio output? Mar 30 at 1:36
  • Works perfectly for me. Just a note on the input volume control -- "Note that the volume of the recording does not depend on your speaker volume. So even when you think the volume of the game sound is really low, it can actually be really loud in the final recording. You should reduce the volume of the game either in the game itself or with PulseAudio Volume Control, so your voice will still be audible. The preview in SimpleScreenRecorder can help you here, it shows the actual volume of the recording." I.e., need some tweaking to get system output and your mic input at the same level.
    – xpt
    Apr 3 at 18:19
  • If you want to give a custom name to this newly created input use: pactl load-module module-null-sink sink_name=combined sink_properties=device.description="\!\!YOUR_CUSTOM_NAME\!\!" instead of pactl load-module module-null-sink sink_name=combined May 31 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.