Skip to content

Instantly share code, notes, and snippets.

@jakebesworth
Created June 26, 2025 20:05
Show Gist options
  • Save jakebesworth/e4940ae421a9561ba403cea27c7c94b3 to your computer and use it in GitHub Desktop.
Save jakebesworth/e4940ae421a9561ba403cea27c7c94b3 to your computer and use it in GitHub Desktop.
Fix Pulse Audio module-echo-cancel crashing or volume changing constantly due to AGC in Ubuntu
#!/usr/bin/env bash
# Create this as a script in ~/microphone.bash && chmod u+x ~/microphone.bash
#
# The goal of this script is to remedy the problem where Chrome/Firefox/Discord/Skype will use Automatic Gain Control
# to change the volume or even crash the echo cancel module. This script will check if the module is loaded every hour
# and if it is not, it will load it. Regardless, it will also set the volume to a desired volume level.
#
# crontab -e
# 0 * * * * export DISPLAY=:0 && export XDG_RUNTIME_DIR=/run/user/$(id -u) && /home/<YOUR USER HERE>/microphone.bash
set -x
LOADED=$(pactl list modules | grep module-echo-cancel)
if [[ -z "${LOADED}" ]]
then
pactl load-module module-echo-cancel 'use_master_format=1 aec_method=webrtc aec_args="analog_gain_control=0 digital_gain_control=0" source_name=echocancel'
pactl set-default-source echocancel
fi
pactl set-source-volume echocancel '98%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment