Real-time Microphone Noise Cancellation on Linux
![Real-time Microphone Noise Cancellation on Linux](/content/images/size/w1200/2024/03/real-time-microphone-noise-cancellation.jpeg)
Free Krisp alternative
Updated: 12–06–2021
Prerequisites:
- PipeWire
- Arch Linux or Fedora
What is Pipewire?
The PipeWire is a multimedia framework built from scratch for very low latency processing of audio/video.
One of the best features of Pipewire is that it provides a real-time capable plugin structure. The PipeWire daemon was built using this framework and is compatible with PulseAudio, JACK, ALSA and GStreamer-based applications.
Is PipeWire a requirement?
No. You can configure this with PulseAudio. However, I have not tested it and verified .
By default, Fedora comes with PipeWire, and most other distributions include the PulseAudio.
This article will focus on configuring the Noise cancelling plugin with PipeWire and creating a Virtual Source to use as an input for any application, even web-based applications like Google Meet and Microsoft teams.
The RNNoise — a noise suppression library based on a recurrent neural network is the foundation of the Noice cancelling plugin.
Follow this link if you are interested in learning how RNNoise library works: https://jmvalin.ca/demo/rnnoise/
The Danylo Piliaiev develops and maintains the plugin, and it eliminates a wide range of noise origins like an aeroplane, construction, office/crowd and computer fans.
1. Plugin Installation
Arch Linux:
To install the plugin on Arch Linux, you must use the noise-suppression-for-voice AUR package.
Read more: AUR — Arch User Repository
Execute the following command to install the package using `yay` an AUR helper.
$ yay -S noise-suppression-for-voice
or you can install without an AUR helper with the following commands:
$ sudo pacman -S git
$ git clone https://aur.archlinux.org/noise-suppression-for-voice.git
$ cd noise-suppression-for-voice
$ makepkg -si
Fedora:
The plugin can be installed on Fedora using the COPR repository. To configure this repository, enter the following command:
$ sudo dnf copr enable ycollet/linuxmao
To install the latest package, enter the following command:
$ sudo dnf install ladspa-noise-suppression-for-voice
Complete the above tasks to install the plugin binary into the location “/usr/lib/ladspa/librnnoise_ladspa.so
”.
2. Create Filter chain for PipeWire
A filter chain provides the capability to insert an arbitrary graph of LADSPA (Linux Audio Developer’s Simple Plugin API) and built-in plugins in front of a sink or a source to create a new Virtual filtered sink/source.
2.1 Create a configuration directory to store filter chain configuration files.
$ mkdir -p ~/.config/pipewire/
2.2 Create a filter chain file with the name “input-filter-chain.conf”.
You can use any name you prefer, but make sure to use it throughout the configuration.
$ vim ~/.config/pipewire/input-filter-chain.conf
You can use this to create a configuration file for a PipeWire filter chain as below.
Notice the first filter graph node has a plugin property that points to the plugin location.
plugin = /usr/lib/ladspa/librnnoise_ladspa.so
Paste the following content to the above file.
3. Persist the configuration
To load this filter chain to the PipeWire, we need to create a systemd service. The service we will be making as a systemd user instance and it will start at the first login.
The systemd user instance is a per-user process and not per-session.
3.1 Create the systemd user configuration directory if it does not exist.
$ mkdir -p ~/.config/systemd/user/
3.2 Create a new systemd unit file.
$ vim ~/.config/systemd/user/pipewire-input-filter-chain.service
Make sure to:
- Replace the file name if you have used a different name for the filter chain configuration file.
- Replace the <username> with your account username.
3.3 Reload systemd user unit files.
$ systemctl --user daemon-reload
3.4 Enable the created systemd service.
$ systemctl --user enable pipewire-input-filter-chain.service
Log out and log back in and check the sound control panel on your DE and you will see a new input source with the name “Noise cancelling source”.
![](https://miro.medium.com/max/1400/1*pXuDJjo8Tvb23DbuvQkcuA.png)
If you do not see the new Virtual Source device, please check the systemd service’s status and rectify any errors in the configuration if the service fails to start.
$ systemctl --user status pipewire-input-filter-chain.service
![](https://miro.medium.com/max/1400/1*AHNb8KFzmFoqbYuvXkxvbQ.png)
4. Finally select the new audio source on applications.
Google Meet
Google meet provides a Noise cancellation option but I have deactivated it as the PipeWire plugin provided better voice quality compared to Google Meet built-in method.
![Google Meet — Microphone configuration](https://miro.medium.com/max/1400/1*b0qaVc1sl6_QCN0-74Fkdw.png)
Slack
![Slack — Audio configuration Microphone](https://miro.medium.com/max/1400/1*zjuTv0J1H-RQPYuxB-9arQ.png)
For other applications, the configuration would be similar.
Now you can make your meetings more effective and enjoy your podcasts and game streams without worrying about the background noise.
References:
- Real-time Noise Suppression Plugin: https://github.com/werman/noise-suppression-for-voice
- AUR repository: https://aur.archlinux.org/packages/noise-suppression-for-voice/
- Photo by Sandra Tenschert on Unsplash