Record two audio sources simultaneously

Have you ever wanted to record microphone sources seperately and had no mixer deck at hand? Here is an interactive bash script that uses pulseaudio to combine two hardware-sources (sinks are also possible) as left and right channel of a new virtual sink. This enables you to use these sources as separable inputs for VoIP applications or home-recording. You can also check it out at pastebin. Of course, you think of altering the remap-module to record two or even more stereo sources as a single virtual multi-channel source. As always, the net helped me a lot with this task.


#    Script to map two pulseaudio hardware input sources as mono inputs
#    to left and right channel of a new loopback-sink respectively. This
#    sink can be used e.g. to use VoIP or record two microphones seperately.
#    Copyright (C) 2013, Henning Hollermann,
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <>.

do_activate() {
    while [ "x" = "x$LEFT" ]; do
        echo "Choose Source for left channel by ID"
        pactl list short sources
        read ID
        LEFT=$(pactl list short sources|awk '/^'$ID'/{print $2}')
    while [ "x" = "x$RIGHT" ]; do
        echo "Choose Source for right channel by ID"
        pactl list short sources | grep -v $LEFT
        read ID
        RIGHT=$(pactl list short sources | grep -v $LEFT|awk '/^'$ID'/{print $2}')
    # Create the name of the Combined sink
    NAME="Combined_Mics:_Left:_"$(echo $LEFT|awk -F'.' '$0=$2')"_Right:_"$(echo $RIGHT|awk -F'.' '$0=$2')

    echo "[LOAD] null sink as \"$NAME\" to connect the two mics to"
    pactl load-module module-null-sink \
            sink_name=combined channels=2 \

    echo "[LOAD] map source 1 ($LEFT) to left channel of \"$NAME\""
    pactl load-module module-remap-source \
            source_name=${LEFT}_left_channel master=$LEFT channels=2 \
            master_channel_map=mono,mono channel_map=left,left
    pactl load-module module-loopback sink=combined source=${LEFT}_left_channel

    echo "[LOAD] map source 2 ($RIGHT) to right channel of \"$NAME\""
    pactl load-module module-remap-source \
            source_name=${RIGHT}_right_channel master=$RIGHT channels=2 \
            master_channel_map=mono,mono channel_map=right,right
    pactl load-module module-loopback sink=combined source=${RIGHT}_right_channel
    echo "[DONE] Now adjust the left and right channel volume of the new sink to be equally loud"

do_deactivate() {
    echo "[UNLOAD] pulseaudio modules..."
    echo "[UNLOAD] module-loopback"
    pactl unload-module module-loopback
    echo "[UNLOAD] module-remap-source"
    pactl unload-module module-remap-source
    echo "[UNLOAD] module-null-sink"
    pactl unload-module module-null-sink

init() {
    for exe in /usr/bin/pulseaudio /usr/bin/pactl; do
        if [ ! -x "$exe" ]; then
            echo "[ERROR] required file $exe not found or not executable"
            exit 1
    [ ! -x /usr/bin/pavucontrol ] && echo "[NOTICE] pavucontrol might be very useful."

case $1 in
    echo "Usage: $0 [enable|disable]";;


Peter Pan. Kann fliegen mit Feenstaub.

Tagged with: , , , ,
Posted in Linux, Musik, Technik

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Posts by topic…
…by month
Have a look at…

%d bloggers like this: