Skip to content

Instantly share code, notes, and snippets.

@hightemp
Created November 23, 2022 15:34
Show Gist options
  • Save hightemp/6d5c9b7f6242cccaaf56ba77ae77e1a0 to your computer and use it in GitHub Desktop.
Save hightemp/6d5c9b7f6242cccaaf56ba77ae77e1a0 to your computer and use it in GitHub Desktop.
autobalancing sound level with pactl
#!/bin/bash
CNT=0
CNT2=0
while :; do
LVL=$(arecord -f S16_LE -qd 1 /tmp/rec.waw && sox /tmp/rec.waw -n stat 2>&1 | awk 'BEGIN{FS=":"} NR==4 {print $2}')
CLVL=$(pactl get-sink-volume @DEFAULT_SINK@ | awk '{ print $5 }' | egrep -o [0-9]+)
echo $CLVL", "$LVL", "$CNT
if (( $(echo "$LVL>0.13" | bc -l) )); then
pactl set-sink-volume @DEFAULT_SINK@ -10%
CNT=20
fi
if (( $(echo "$LVL<0.08" | bc -l) )); then
if (( $(echo "$CNT>0" | bc -l) )); then
CNT=$(( $CNT - 1 ))
else
if (( $(echo "$CLVL<100" | bc -l) )); then
pactl set-sink-volume @DEFAULT_SINK@ +10%
fi
fi
else
CNT=20
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment