Skip to content

Instantly share code, notes, and snippets.

@simonesestito
Created January 19, 2024 08:37
Show Gist options
  • Save simonesestito/d2d5b3e572233b8be7fd512adb509b09 to your computer and use it in GitHub Desktop.
Save simonesestito/d2d5b3e572233b8be7fd512adb509b09 to your computer and use it in GitHub Desktop.
PulseAudio: use multiple speakers
#!/bin/bash
# TODO: Update this strings with the actual values for your speakers
# TODO: Remember to also adjust the volumes to balance them (depending on their power and their distance from your location)
SPEAKER_1_NAME=alsa_output.pci-0000_03_00.1.hdmi-stereo
SPEAKER_1_VOLUME=80%
SPEAKER_2_NAME=alsa_output.pci-0000_03_00.6.analog-stereo
SPEAKER_2_VOLUME=100%
# Initially, remove previous state
pactl unload-module module-null-sink 2>/dev/null
pactl unload-module module-loopback 2>/dev/null
set -e
# 1. Create a fake sink null called "Dual Monitor"
pactl load-module module-null-sink sink_name=Dual_Monitor sink_properties=device.description="Dual_Monitor"
# 2. Connect fake sink to SPEAKER_1
pactl load-module module-loopback source=Dual_Monitor.monitor "sink=$SPEAKER_1_NAME" channels=2
# 3. Connect fake sink to SPEAKER_2
pactl load-module module-loopback source=Dual_Monitor.monitor "sink=$SPEAKER_2_NAME" channels=2
# 4. Set volume of Dual_monitor to 50%
pactl set-sink-mute Dual_Monitor false
pactl set-sink-volume Dual_Monitor 50%
# 5. Set volume of SPEAKER_1
pactl set-sink-mute $SPEAKER_1_NAME false
pactl set-sink-volume $SPEAKER_1_NAME $SPEAKER_1_VOLUME
# 6. Set volume of SPEAKER_2
pactl set-sink-mute $SPEAKER_2_NAME false
pactl set-sink-volume $SPEAKER_2_NAME $SPEAKER_2_VOLUME
# 7. Set the fake sink as the default audio sink
pactl set-default-sink Dual_Monitor
echo "Setup completed."
echo
echo "================="
echo "Are you using Gnome and the mic indicator pops up when you are not using the mic?"
echo "Check out: https://gist.github.com/simonesestito/ef4ea0c1af420d474d29a9a20d375d80"
echo "================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment