audio --switch

This commit is contained in:
2026-03-04 08:37:22 +08:00
parent 939289f172
commit c99b5a2117

View File

@@ -2,43 +2,74 @@
# available sinks listed here: pactl list sinks # available sinks listed here: pactl list sinks
CURRENT_SINK="$(pactl get-default-sink)"
CURRENT_PRESET="$(easyeffects --active-preset output)"
LOUD_SINK="alsa_output.pci-0000_00_1f.3.analog-stereo" LOUD_SINK="alsa_output.pci-0000_00_1f.3.analog-stereo"
LOUD_PRESET="Defender" LOUD_PRESET="Defender"
HEAD_SINK="alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo" HEAD_SINK="alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo"
HEAD_PRESET="Techno" HEAD_PRESET="Techno"
set_head() {
if [ "$CURRENT_SINK" != "$HEAD_SINK" ]; then
pactl set-default-sink "$HEAD_SINK" || exit 1
easyeffects --load-preset "$HEAD_PRESET" || exit 2
echo -e "Current sink\t: $HEAD_SINK"
echo -e "Current preset\t: $HEAD_PRESET"
fi
}
set_loud() {
if [ "$CURRENT_SINK" != "$LOUD_SINK" ]; then
pactl set-default-sink "$LOUD_SINK" || exit 1
easyeffects --load-preset "$LOUD_PRESET" || exit 2
echo -e "Current sink\t: $LOUD_SINK"
echo -e "Current preset\t: $LOUD_PRESET"
fi
}
show_help() {
echo "Usage: $(basename "$0") [-h|--help|--loud|--head|--switch]"
echo
echo "Switch audio output and apply appropriate easyffects preset."
echo
echo "Options:"
echo " -h, --help Show this help message"
echo " --loud Enable loud speakers"
echo " --head Enable headphones"
echo " --switch Switch between loud and headphones"
echo
}
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo -e "Current sink\t: $(pactl get-default-sink)"
echo -e "Loud sink\t: $LOUD_SINK" echo -e "Loud sink\t: $LOUD_SINK"
echo -e "Loud preset\t: $LOUD_PRESET" echo -e "Loud preset\t: $LOUD_PRESET"
echo -e "Head sink\t: $HEAD_SINK" echo -e "Head sink\t: $HEAD_SINK"
echo -e "Head preset\t: $HEAD_PRESET" echo -e "Head preset\t: $HEAD_PRESET"
echo
echo -e "Current sink\t: $CURRENT_SINK"
echo -e "Current preset\t: $CURRENT_PRESET"
exit exit
fi fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
cat <<EOF show_help
Usage: $(basename "$0") [-h]
Switch audio output and apply appropriate easyffects preset.
Options:
-h, --help Show this help message
--loud Enable loud speakers
--head Enable headphones
EOF
exit exit
fi fi
if [ "$1" == "--loud" ]; then if [ "$1" == "--loud" ]; then
pactl set-default-sink "$LOUD_SINK" || exit 1 set_loud
easyeffects -l "$LOUD_PRESET" || exit 2
exit exit
fi fi
if [ "$1" == "--head" ]; then if [ "$1" == "--head" ]; then
pactl set-default-sink "$HEAD_SINK" || exit 1 set_head
easyeffects -l "$HEAD_PRESET" || exit 2
exit exit
fi fi
if [ "$1" == "--switch" ]; then
case "$CURRENT_SINK" in
*$LOUD_SINK*) set_head ;;
*$HEAD_SINK*) set_loud ;;
*) show_help ;;
esac
fi