Skip to content

Instantly share code, notes, and snippets.

@D3SOX
Last active November 5, 2023 11:06
Show Gist options
  • Save D3SOX/52eedee149022716991444972c4eb58f to your computer and use it in GitHub Desktop.
Save D3SOX/52eedee149022716991444972c4eb58f to your computer and use it in GitHub Desktop.
PipeWire default mic RNNoise

Prerequisites

Your distribution must use PipeWire as default audio server. To confirm this run pactl info and make sure it includes a line similar to:

Server Name: PulseAudio (on PipeWire 0.3.83)

Install packages

For Arch: sudo pacman -S rnnoise noise-suppression-for-voice

If you know how to install it on other distributions please leave a comment so I can add it here

Setup filter chain

mkdir -p ~/.config/pipewire/filter-chains

Edit ~/.config/pipewire/filter-chains/source-noise-suppression.conf

# Noise canceling source
#
# start with pipewire -c filter-chain/source-rnnoise.conf
#
context.properties = {
    log.level = 2
}
context.spa-libs = {
    audio.convert.* = audioconvert/libspa-audioconvert
    support.*       = support/libspa-support
}
context.modules = [
    { name = libpipewire-module-rt
        args = {
            #rt.prio      = 88
            #rt.time.soft = -1
            #rt.time.hard = -1
        }
        flags = [ ifexists nofail ]
    }
    { name = libpipewire-module-protocol-native }
    { name = libpipewire-module-client-node }
    { name = libpipewire-module-adapter }
    { name = libpipewire-module-filter-chain
        args = {
            node.name        = "effect_input.audio_cleaner"
            node.description = "Audio Cleaner"
            audio.channels   = 1
            audio.position = [ MONO ]
            media.name       = "On The Fly Audio Cleanup"
            filter.graph = {
                nodes = [
                    {
                        type   = ladspa
                        name   = rnnoise
                        plugin = librnnoise_ladspa
                        label  = noise_suppressor_mono
                        control = {
                            # Input
                            # Output
                            "VAD Threshold (%)" 75.0
                        }
                    }
             
                ]
      
            }
            capture.props = {
                node.passive = true
                audio.channels = 1
                audio.position = [ MONO ]
      
            }
            playback.props = {
                audio.channels = 1
                media.class = Audio/Source
                audio.position = [ MONO ]
              
              
            }
        }
    }
    
]

Setup systemd user service

mkdir -p ~/.config/systemd/user

Edit ~/.config/systemd/user/pipewire-input-filter-chain.service

[Unit]
Description=PipeWire Input Filter Chain
After=pipewire.service
BindsTo=pipewire.service

[Service]
ExecStart=/usr/bin/pipewire -c /home/nico/.config/pipewire/filter-chains/source-noise-suppression.conf
Type=simple
Restart=on-failure

[Install]
WantedBy=pipewire.service

Make sure to change nico to your username!

sed -i "s/nico/$USER/" ~/.config/systemd/user/pipewire-input-filter-chain.service

Enable and start now with

systemctl --user enable --now pipewire-input-filter-chain.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment