From fa814c6bff460dc4faeab151d1cb14208da517ec Mon Sep 17 00:00:00 2001 From: zino Date: Wed, 17 Apr 2024 11:56:54 +0200 Subject: [PATCH] Add fix_mic_volume.sh --- fix_mic_volume.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 fix_mic_volume.sh diff --git a/fix_mic_volume.sh b/fix_mic_volume.sh new file mode 100644 index 0000000..96fe107 --- /dev/null +++ b/fix_mic_volume.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +VOLUME_LEVEL=56000 +SOURCE_NAME="alsa_input.usb-Samson_Technologies_Samson_Meteor_Mic-00.analog-stereo" + +# Get the current source index by its name +get_source_index_by_name() { + pactl list sources short | grep "$SOURCE_NAME" | cut -f1 +} + +# Adjust microphone volume +adjust_volume() { + pactl set-source-volume "$SOURCE_NAME" $VOLUME_LEVEL +} + +# Initially adjust +adjust_volume + +# Get the current source index for the given name +SOURCE_INDEX=$(get_source_index_by_name) + +# Listen for volume changes and adjust if needed +pactl subscribe | grep --line-buffered "source #$SOURCE_INDEX" | while read -r line ; do + if echo "$line" | grep -q "Event 'change' on source #$SOURCE_INDEX"; then + adjust_volume + fi +done