You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
#!/usr/bin/env sh
|
|
|
|
delay=$1
|
|
usage='Usage: st [delay_in_milliseconds]\n\nThis utility will toggle sidetone for your primary audio input device.\nDelay argument is optional -- default: 1\n'
|
|
# Sanity check
|
|
### Set delay to 1 if unspecified
|
|
if [ $# -eq 0 ]; then
|
|
delay=1
|
|
fi
|
|
|
|
### Check if pavucontrol is available
|
|
if (! type pactl &>/dev/null); then
|
|
printf "ERROR 12: 'pactl' command not found!\n\n This command is part of PulseAudio Volume Control, which may commonly be found in your distribution's repository as 'pavucontrol'.\n Please install and try again." >&2
|
|
exit 12
|
|
fi
|
|
|
|
### Check if delay value >1
|
|
if [ $delay -lt 1 ]; then
|
|
echo "ERROR 13: Delay can not be less than 1!" >&2
|
|
printf "\n$usage"
|
|
exit 13
|
|
fi
|
|
|
|
### Check if delay value is an integer (no extra characters)
|
|
case $delay in
|
|
''|*[!0-9]*)
|
|
echo "ERROR 14: Delay value must be an unsigned integer!" >&2 ;
|
|
printf "\n$usage" ;
|
|
exit 14 ;;
|
|
esac
|
|
# End sanity check
|
|
|
|
|
|
if (pactl list | grep module-loopback) 2>&1 >/dev/null; then
|
|
pactl unload-module module-loopback
|
|
echo "Sidetone: OFF"
|
|
exit 0
|
|
else
|
|
pactl load-module module-loopback latency_msec=${delay} >/dev/null || exit 1
|
|
if [ $delay -gt 1 ]; then
|
|
printf "Sidetone: ON\tDelay: ${delay}ms\n"
|
|
else
|
|
echo "Sidetone: ON"
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
|
|
echo "ERROR 3: We don't know WTF happened!" >&2
|
|
exit 3
|
|
|