Created
December 7, 2022 01:22
-
-
Save nofishleft/2c888c95326e08fbe5ccb9ed69e97946 to your computer and use it in GitHub Desktop.
Linux microphone switching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Name of the device in pactl, use the following to discover names | |
# pactl list sources | grep -e 'Name' -e 'Description' | |
steel_series='alsa_input.usb-SteelSeries_Arctis_Pro_Wireless-00.analog-mono' | |
snowball='alsa_input.usb-BLUE_MICROPHONE_Blue_Snowball_201712-00.analog-stereo' | |
# Get the active source, ideally would use 'pactl get-default-source', | |
# but that isn't supported in my version of pulseaudio, | |
# Should be noted that this work around may break if there are multiple sources that are being used | |
active_source=`pactl list short sources | grep 'RUNNING' | cut -f 2` | |
# Change the default input device, and switch all applications actively using an input device to the new device | |
# Usage: set_source NAME|ID | |
function set_source() { | |
echo "Switching to $1" | |
# Change default input device | |
pactl set-default-source "$1" | |
# Move applications over to new device | |
pactl list short source-outputs | while read stream; do | |
streamId=`echo $stream|cut -f1` | |
pactl move-source-output "$streamId" "$1" | |
done | |
} | |
if [ "$active_source" = "$steel_series" ]; then | |
set_source "$snowball" | |
elif [ "$active_source" = "$snowball" ]; then | |
set_source "$steel_series" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment