2020-06-25 05:01:00 +02:00
|
|
|
# Configures a running Pulseaudio instance with an LADSP filter that
|
|
|
|
# creates a noise-cancelling sink.
|
|
|
|
#
|
|
|
|
# This can be used to, for example, cancel noise from an incoming
|
|
|
|
# video conferencing audio stream.
|
|
|
|
#
|
|
|
|
# There are some caveats, for example this will not distinguish
|
|
|
|
# between noise from different participants and I have no idea what
|
|
|
|
# happens if the default sink goes away.
|
2020-06-26 05:38:26 +02:00
|
|
|
#
|
|
|
|
# If this script is run while an NSFV sink exists, the existing sink
|
|
|
|
# will first be removed.
|
2021-04-10 02:13:18 +02:00
|
|
|
{ depot, pkgs, ... }:
|
2020-06-25 05:01:00 +02:00
|
|
|
|
|
|
|
let
|
2021-04-10 02:13:18 +02:00
|
|
|
inherit (pkgs) ripgrep pulseaudio;
|
|
|
|
inherit (depot.third_party) nsfv;
|
2020-06-25 05:01:00 +02:00
|
|
|
in
|
|
|
|
pkgs.writeShellScriptBin "nsfv-setup" ''
|
2020-06-26 05:38:26 +02:00
|
|
|
export PATH="${ripgrep}/bin:${pulseaudio}/bin:$PATH"
|
|
|
|
|
|
|
|
if pacmd list-sinks | rg librnnoise_ladspa.so >/dev/null; then
|
|
|
|
pactl unload-module module-ladspa-sink
|
|
|
|
fi
|
|
|
|
|
2020-06-25 05:01:00 +02:00
|
|
|
SINK=$(${pulseaudio}/bin/pacmd info | ${ripgrep}/bin/rg -r '$1' '^Default sink name: (.*)$')
|
|
|
|
echo "Setting up NSFV filtering to sink ''${SINK}"
|
2021-04-10 02:13:18 +02:00
|
|
|
${pulseaudio}/bin/pacmd load-module module-ladspa-sink sink_name=NSFV sink_master=''${SINK} label=noise_suppressor_mono plugin=${nsfv}/lib/ladspa/librnnoise_ladspa.so control=42 rate=48000
|
2020-06-25 05:01:00 +02:00
|
|
|
''
|