PulseAudio comes with a module that can be used to perform acoustic echo cancellation of the microphone input, and some background noise reduction. This module is not enabled by default on most (if not all) Linux distributions, so this article will show you how to enable it.
I’ll show you 2 ways of enabling the PulseAudio Echo Cancel module: one that makes it permanent so it’s automatically started when you login to your desktop, and another one that allows you to enable echo cancellation on demand, when you need it.
This is not just to offer 2 alternatives, but also to work around a PulseAudio bug that happens for example when plugging in a headset after loading the Echo Cancel module, which causes this not to switch automatically to the new
sink_master. Also, in my case, having module-echo-cancel load at startup does not work at all (I’m not sure why), but it can be loaded after logging in with no issues, using the second method below.
How to enable the PulseAudio module-echo-cancel on startup
To always have echo / noise cancellation on your Linux desktop using PulseAudio, having module-echo-cancel loaded at startup, follow the steps below.
/etc/pulse/default.pa as root with a text editor, like Nano (command line text editor) for example:
sudo nano /etc/pulse/default.pa
Scroll down to the end of this file and paste the following:
load-module module-echo-cancel aec_method=webrtc source_name=echocancel sink_name=echocancel1
This is what this does: if your system PulseAudio is compiled with the echo / noise cancellation module, load this module, use webrtc as the echo cancellation method (it should be better than the default speex), specify a source and sink names, then set that source and sink as default.
2. After saving the file, reload PulseAudio using this command:
Or reboot your computer.
After this, look in your system’s sound settings and the input and output devices should both have the default name, but with “echo cancelled with…” in parentheses, e.g. “Built-in Audio Analog Stereo (echo cancelled with Built-in Audio Analog Stereo)” like in the screenshot at the top of the article.
This should persist through reboots.
If this doesn’t work for you, see the second method below, for how to load module-echo-cancel on demand.
How to enable the PulseAudio module-echo-cancel on demand
To have echo / noise cancellation of the microphone input only when you need it (by having an application menu entry to turn this on), follow the steps below.
1. Create a new file in your home folder called
echocancel with the following contents:
pactl unload-module module-echo-cancel
pactl load-module module-echo-cancel aec_method=webrtc source_name=echocancel sink_name=echocancel1
pacmd set-default-source echocancel
pacmd set-default-sink echocancel1
This unloads module-echo-cancel if it was already loaded, then loads this module with webrtc as the echo cancellation method (it should be better than the default speex), specify a source and sink names, then set that source and sink as default.
2. After saving the file, make it executable and copy it somewhere in your path. You can make it executable and place it in
/usr/local/bin using this command:
sudo install echocancel /usr/local/bin
3. Create a file called
echocancel.desktop in your home folder with the following contents:
Name=Echo Cancel PulseAudio Module
Comment=Load the PulseAudio module-echo-cancel
4. Save the file and copy it to
~/.local/share/applications/, e.g. do this from the command line using:
cp echocancel.desktop ~/.local/share/applications/
You should now see a new entry called
Echo Cancel PulseAudio Module in your applications menu. When you click on it, it should load the echo / noise cancelling PulseAudio volume.
After you run this, look in your system’s sound settings and the input and output devices should both have the default name, but with “echo cancelled with…” in parentheses, like in the screenshot at the top of the article.
In case you want to unload the echo cancel PulseAudio module you can run:
pactl unload-module module-echo-cancel
For more on this, see the PulseAudio module-echo-cancel documentation.