Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active January 9, 2025 12:11
Show Gist options
  • Save plembo/ec918f30978c4029cf394c507f79d52a to your computer and use it in GitHub Desktop.
Save plembo/ec918f30978c4029cf394c507f79d52a to your computer and use it in GitHub Desktop.
Mixing Audio with Linux

Mixing Audio with Linux

Simple procedure for bare bones audio mixing with Linux. Sample case is a voiceover of some audio content. PulseAudio loopback will allow mixing of mic input with some other audio input (like music being played in a browser) and recording in audacity by selecting "Monitor of Built-in Analog Stereo" as input on the Recording tab of pavucontrol.

Thanks to Iñigo Aldazabal (iamc) for the code.

My Setup

  • Ubuntu 18.04 LTS with Gnome Shell.
  • Both pavucontrol and audacity installed.
  • Samson Q1U usb microphone.

Configuration

Only my primary mic, the Q1U is connected.

Configuration tab in pavucontrol:

  • ATI HDMI is Off
  • Q1Y dynamic microphone set to Analog Mono Input
  • Bult-in Audio set to Analog Stereo Duplex

Audacity preferences under Devices... Interface:

  • Playback device: pulse
  • Recording device Device: Samson Q1U: USB Audio (hw:1,0)
  • Recording device Channels: 1 (Mono)

Use the following script (micloopback) to turn pulseaudio loopback on and off:

#!/bin/bash
# Loads / unloads pulseaudio loopback module in order to eg. be redirect
# mic input to headphones.
# Usage: micloopback [on|off]
#
if [ $# -ne 1 ]; then
    echo "Usage: $0 [on|off]" 
    exit 1
fi
if [[ $1 == "on"  ]]; then
    pactl load-module module-loopback latency_msec=1
    echo "pulseaudio loopback module loaded"
elif [[ $1 == "off" ]]; then
    pactl unload-module module-loopback
    echo "pulseaudio loopback module unloaded"
else
    echo "Usage: $0 [on|off]" 
fi

I placed mine under ~/bin/ and set it executable.

Test

  1. Enable pulseaudio loopback:
$ micloopback on
  1. Open audacity.

  2. Open content you want to mix. Here's a fairly long sample:

    https://youtu.be/smE-uIljiGo

  3. Hit record on audacity and start your sample audio.

  4. Go to pavucontrol, Recording tab, and set "Monitor of Built-in Analog Stereo".

  5. Start talking into mic.

  6. Stop recording in audacity and stop sample audio. Stop talking.

  7. Turn off loopback:

$ micloopback off
  1. Play back audacity recording to confirm voiceover worked..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment