Created
November 23, 2022 15:34
-
-
Save hightemp/6d5c9b7f6242cccaaf56ba77ae77e1a0 to your computer and use it in GitHub Desktop.
autobalancing sound level with pactl
This file contains hidden or 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 | |
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