Skip to content

About

DeepFilterNet fork: real-time safe LADSPA noise suppression for PipeWire, KDE tray app DeepFilter Tray, prebuilt plugins, AUR packages (based on Rikorose/DeepFilterNet)

Resources

Stars

1 star

Watchers

0 watching

Forks

 
 

Repository files navigation

DeepFilterNet – real-time noise suppression for PipeWire

Real-time speech enhancement (noise suppression) for the microphone on Linux: a real-time safe LADSPA plugin for PipeWire filter chains with the DeepFilterNet3 models, a KDE Plasma tray app to tune it live, prebuilt plugins and Arch Linux packages.

This repository is a fork of Rikorose/DeepFilterNet and based on the work of Hendrik Schröter and the DeepFilterNet authors (models, framework, libDF, the original LADSPA plugin). Like the original, all code and model weights are dual-licensed under the MIT or Apache 2.0 license, see License. Upstream changes are merged regularly; the models, the Python framework and the training code are unchanged. Prebuilt plugins are on the releases page (tags ladspa-v*).

What this repository contains

Directory Purpose
ladspa/ the LADSPA plugin for PipeWire (virtual noise-suppressed microphone) – real-time safe in this fork
tray/ DeepFilter Tray (new in this fork): KDE Plasma tray app to tune the running plugin live
libDF/ the Rust DSP and inference library (allocation-free processing in this fork)
packaging/aur/ Arch Linux packages: deepfilternet-ladspa-bin, deepfilternet-ladspa-git, deepfilter-tray-git
compile.sh builds and installs the plugin for the local CPU
models/ the DeepFilterNet models (unchanged)
DeepFilterNet/, pyDF/, pyDF-data/ the Python framework and training code (unchanged)

Features of this fork

LADSPA plugin

  • Real-time safe: the audio thread does not allocate, block, log or spin, not even when controls change.
  • Processing on its own worker thread with real-time priority (SCHED_FIFO, else RTKit over D-Bus).
  • Robust: clean unload and suspend/resume, the model loaded once, audio passed through instead of a crash on an unsupported sample rate or a worker failure, panic = "unwind" so a panic cannot abort PipeWire.
  • Predictable latency (configurable output reserve), underrun/overload reports, live metrics over D-Bus (levels, SNR estimate, processing stage, CPU time).
  • Only the chosen model is embedded: normal DeepFilterNet3 or the low latency model.

libDF

  • No per-frame allocations, reused FFT buffers, a simpler post filter.
  • Digital silence (muted microphone): the network is skipped after 5 silent frames, and long silence can no longer turn the output into NaN (upstream issue #713).

Tools, packaging, build

  • DeepFilter Tray: live sliders, bypass, metrics, presets, writing the values back into the filter-chain configuration, command line.
  • Prebuilt plugins for x86_64, aarch64 and armv7 (GitHub workflow), Arch Linux packages, compile.sh for the local CPU.
  • Current dependencies (tract 0.23, ndarray 0.17, pyo3 0.30, zbus 6, …), lockfile updated for security advisories.

For PipeWire integration as a virtual noise suppression microphone see ladspa/README.md.

DeepFilter Tray (tray/)

DeepFilter Tray

DeepFilter Tray is a small KDE Plasma system tray app for this fork. It tunes the plugin live while it runs in a PipeWire filter chain:

  • sliders for all plugin controls, applied immediately, and a bypass switch;
  • a live view of what the plugin does: levels in and out, estimated SNR next to the threshold sliders, the processing stage of the last 100 ms and which threshold decided it, CPU time per frame; a speech indicator on the tray icon;
  • named presets, chosen from a drop-down list or the tray menu, optionally applied whenever the filter chain starts;
  • From config goes back to the values in the filter-chain configuration, Write to config... saves the current values into it (only the numbers change, comments stay, a backup is kept);
  • a command line for scripts: deepfilter-tray --list, --set, --preset, --from-config, --write-config.

It talks to PipeWire directly (no D-Bus build of the plugin needed) and finds every running filter chain with the plugin. Build it from tray/ (Qt 6, KDE Frameworks 6, libpipewire) or install deepfilter-tray-git from packaging/aur/.

Changes compared to upstream in detail

LADSPA plugin (ladspa/)

  • Real-time safe audio thread: run() doesn't allocate, block, log or spin, not even when controls change. Control changes go through a bounded channel with try_send, so a burst of automation can't grow memory.
  • Processing runs on its own worker thread with real-time priority (SCHED_FIFO). If that isn't allowed, it falls back to RTKit over D-Bus (Cargo feature rtkit, on by default).
  • Lifecycle fixes:
    • The worker is joined when the host unloads the plugin, so no thread or memory leaks.
    • The model is loaded once per instance.
    • Suspend/resume (deactivate/activate) works.
  • More robust: if the sample rate isn't 48 kHz or the worker fails, the plugin passes the audio through instead of crashing the host. The plugin is built with panic = "unwind" (Cargo profile release-ladspa) so a panic can't abort PipeWire.
  • Min Processing Buffer (frames) sets the output reserve, which keeps latency predictable: (1 + frames) × 10 ms plus the model's lookahead. The reserve is kept when the queue is trimmed. The plugin logs output underruns and overloads, at most once per second.
  • Live metrics over D-Bus for monitoring tools (levels, SNR estimate, processing stage, CPU time, underruns), collected only while a client holds a lease and never on the audio thread; see ladspa/README.md.
  • The unmaintained ladspa crate is replaced by a small built-in FFI layer (ladspa/src/ffi.rs).
  • The model is chosen at build time and only that one is embedded:
    • Cargo feature default-model-ll (default): the low latency model.
    • --no-default-features --features default-model,rtkit,dbus: the normal DeepFilterNet3 model. It has 20 ms more lookahead and needs about 40 % of the CPU time of the low latency model.
  • Fixed flaky thread-count tests, and added a test that control changes don't allocate.

libDF

  • DfTract::process doesn't allocate per frame. Rolling spectrum buffers, encoder input and synthesis buffers are reused instead of cloned. All-zero masks are applied without a new tensor.
  • DFState analysis/synthesis reuse their FFT buffers.
  • The post filter is simpler and now also processes the last frequency bin (changes the output by at most 1 LSB). Everything else gives bit-identical output.
  • The clipping warning is logged at most once per second instead of every frame.
  • Digital silence (e.g. a muted microphone) works as intended: after 5 silent frames the network is skipped until a signal comes back, which saves CPU, and a silent frequency bin can no longer turn the output into NaN after long silence (upstream issue #713). Audio without digital silence gives bit-identical output.

Dependencies and build

  • Dependencies updated: tract 0.23, ndarray 0.17, pyo3/numpy 0.30, rubato 1.0, rand 0.9, thiserror 2, itertools 0.15, rustfft 6.4 / realfft 3.5, zbus 6, and hdf5-metno instead of a pinned git revision of hdf5-rust. The lockfile is updated for security advisories, and the MSRV is now 1.85.
  • compile.sh builds the plugin for the local CPU (target-cpu=native) with the normal DFN3 model (MODEL=ll ./compile.sh builds the low latency model). It installs the plugin to ~/.local/lib/ladspa/.
  • tray/: DeepFilter Tray, see above.
  • Arch Linux packages in packaging/aur/: deepfilternet-ladspa-bin (the prebuilt release plugin) and deepfilternet-ladspa-git (built from main, _model=ll makepkg for the low latency model), plus deepfilter-tray-git for the tray app. The two plugin packages install /usr/lib/ladspa/libdeep_filter_ladspa.so and conflict with other packages providing libdeep_filter_ladspa. packaging/aur/update-bin.sh <tag> updates the -bin package to a new release.
  • Release builds use codegen-units = 1.
  • The GitHub workflow .github/workflows/ladspa-release.yml builds portable plugins for x86_64, aarch64 and armv7 with both models. It publishes them as a release when a ladspa-v* tag is pushed. The upstream workflows are disabled in this fork.
  • CLAUDE.md with build and test commands for working on the code.

Upstream DeepFilterNet

A Low Complexity Speech Enhancement Framework for Full-Band Audio (48kHz) using on Deep Filtering.

deepfilternet3

Demo

DeepFilterNet-Demo-new.mp4

To run the demo (linux only) use:

cargo +nightly run -p df-demo --features ui --bin df-demo --release

News

Usage

deep-filter

Download a pre-compiled deep-filter binary from the release page. You can use deep-filter to suppress noise in noisy .wav audio files. Currently, only wav files with a sampling rate of 48kHz are supported.

USAGE:
    deep-filter [OPTIONS] [FILES]...

ARGS:
    <FILES>...

OPTIONS:
    -D, --compensate-delay
            Compensate delay of STFT and model lookahead
    -h, --help
            Print help information
    -m, --model <MODEL>
            Path to model tar.gz. Defaults to DeepFilterNet2.
    -o, --out-dir <OUT_DIR>
            [default: out]
    --pf
            Enable postfilter
    -v, --verbose
            Logging verbosity
    -V, --version
            Print version information

If you want to use the pytorch backend e.g. for GPU processing, see further below for the Python usage.

DeepFilterNet Framework

This framework supports Linux, MacOS and Windows. Training is only tested under Linux. The framework is structured as follows:

  • libDF contains Rust code used for data loading and augmentation.
  • DeepFilterNet contains DeepFilterNet code training, evaluation and visualization as well as pretrained model weights.
  • pyDF contains a Python wrapper of libDF STFT/ISTFT processing loop.
  • pyDF-data contains a Python wrapper of libDF dataset functionality and provides a pytorch data loader.
  • ladspa contains a LADSPA plugin for real-time noise suppression.
  • models contains pretrained for usage in DeepFilterNet (Python) or libDF/deep-filter (Rust)

DeepFilterNet Python: PyPI

Install the DeepFilterNet Python wheel via pip:

# Install cpu/cuda pytorch (>=1.9) dependency from pytorch.org, e.g.:
pip install torch torchaudio -f https://download.pytorch.org/whl/cpu/torch_stable.html
# Install DeepFilterNet
pip install deepfilternet
# Or install DeepFilterNet including data loading functionality for training (Linux only)
pip install deepfilternet[train]

To enhance noisy audio files using DeepFilterNet run

# Specify an output directory with --output-dir [OUTPUT_DIR]
deepFilter path/to/noisy_audio.wav

Manual Installation

Install cargo via rustup. Usage of a conda or virtualenv recommended. Please read the comments and only execute the commands that you need.

Installation of python dependencies and libDF:

cd path/to/DeepFilterNet/  # cd into repository
# Recommended: Install or activate a python env
# Mandatory: Install cpu/cuda pytorch (>=1.8) dependency from pytorch.org, e.g.:
pip install torch torchaudio -f https://download.pytorch.org/whl/cpu/torch_stable.html
# Install build dependencies used to compile libdf and DeepFilterNet python wheels
pip install maturin poetry

#  Install remaining DeepFilterNet python dependencies
# *Option A:* Install DeepFilterNet python wheel globally within your environment. Do this if you want use
# this repos as is, and don't want to develop within this repository.
poetry -C DeepFilterNet install -E train -E eval
# *Option B:* If you want to develop within this repo, install only dependencies and work with the repository version
poetry -C DeepFilterNet install -E train -E eval --no-root
export PYTHONPATH=$PWD/DeepFilterNet # And set the python path correctly

# Build and install libdf python package required for enhance.py
maturin develop --release -m pyDF/Cargo.toml
# *Optional*: Install libdfdata python package with dataset and dataloading functionality for training
# Required build dependency: HDF5 headers (e.g. ubuntu: libhdf5-dev)
maturin develop --release -m pyDF-data/Cargo.toml
# If you have troubles with hdf5 you may try to build and link hdf5 statically:
maturin develop --release --features hdf5-static -m pyDF-data/Cargo.toml

Use DeepFilterNet from command line

To enhance noisy audio files using DeepFilterNet run

$ python DeepFilterNet/df/enhance.py --help
usage: enhance.py [-h] [--model-base-dir MODEL_BASE_DIR] [--pf] [--output-dir OUTPUT_DIR] [--log-level LOG_LEVEL] [--compensate-delay]
                  noisy_audio_files [noisy_audio_files ...]

positional arguments:
  noisy_audio_files     List of noise files to mix with the clean speech file.

optional arguments:
  -h, --help            show this help message and exit
  --model-base-dir MODEL_BASE_DIR, -m MODEL_BASE_DIR
                        Model directory containing checkpoints and config.
                        To load a pretrained model, you may just provide the model name, e.g. `DeepFilterNet`.
                        By default, the pretrained DeepFilterNet2 model is loaded.
  --pf                  Post-filter that slightly over-attenuates very noisy sections.
  --output-dir OUTPUT_DIR, -o OUTPUT_DIR
                        Directory in which the enhanced audio files will be stored.
  --log-level LOG_LEVEL
                        Logger verbosity. Can be one of (debug, info, error, none)
  --compensate-delay, -D
                        Add some paddig to compensate the delay introduced by the real-time STFT/ISTFT implementation.

# Enhance audio with original DeepFilterNet
python DeepFilterNet/df/enhance.py -m DeepFilterNet path/to/noisy_audio.wav

# Enhance audio with DeepFilterNet2
python DeepFilterNet/df/enhance.py -m DeepFilterNet2 path/to/noisy_audio.wav

Use DeepFilterNet within your Python script

from df import enhance, init_df

model, df_state, _ = init_df()  # Load default model
enhanced_audio = enhance(model, df_state, noisy_audio)

See here for a full example.

Training

The entry point is DeepFilterNet/df/train.py. It expects a data directory containing HDF5 dataset as well as a dataset configuration json file.

So, you first need to create your datasets in HDF5 format. Each dataset typically only holds training, validation, or test set of noise, speech or RIRs.

# Install additional dependencies for dataset creation
pip install h5py librosa soundfile
# Go to DeepFilterNet python package
cd path/to/DeepFilterNet/DeepFilterNet
# Prepare text file (e.g. called training_set.txt) containing paths to .wav files
#
# usage: prepare_data.py [-h] [--num_workers NUM_WORKERS] [--max_freq MAX_FREQ] [--sr SR] [--dtype DTYPE]
#                        [--codec CODEC] [--mono] [--compression COMPRESSION]
#                        type audio_files hdf5_db
#
# where:
#   type: One of `speech`, `noise`, `rir`
#   audio_files: Text file containing paths to audio files to include in the dataset
#   hdf5_db: Output HDF5 dataset.
python df/scripts/prepare_data.py --sr 48000 speech training_set.txt TRAIN_SET_SPEECH.hdf5

All datasets should be made available in one dataset folder for the train script.

The dataset configuration file should contain 3 entries: "train", "valid", "test". Each of those contains a list of datasets (e.g. a speech, noise and a RIR dataset). You can use multiple speech or noise dataset. Optionally, a sampling factor may be specified that can be used to over/under-sample the dataset. Say, you have a specific dataset with transient noises and want to increase the amount of non-stationary noises by oversampling. In most cases you want to set this factor to 1.

Dataset config example:

dataset.cfg

{
  "train": [
    [
      "TRAIN_SET_SPEECH.hdf5",
      1.0
    ],
    [
      "TRAIN_SET_NOISE.hdf5",
      1.0
    ],
    [
      "TRAIN_SET_RIR.hdf5",
      1.0
    ]
  ],
  "valid": [
    [
      "VALID_SET_SPEECH.hdf5",
      1.0
    ],
    [
      "VALID_SET_NOISE.hdf5",
      1.0
    ],
    [
      "VALID_SET_RIR.hdf5",
      1.0
    ]
  ],
  "test": [
    [
      "TEST_SET_SPEECH.hdf5",
      1.0
    ],
    [
      "TEST_SET_NOISE.hdf5",
      1.0
    ],
    [
      "TEST_SET_RIR.hdf5",
      1.0
    ]
  ]
}

Finally, start the training script. The training script may create a model base_dir if not existing used for logging, some audio samples, model checkpoints, and config. If no config file is found, it will create a default config. See DeepFilterNet/pretrained_models/DeepFilterNet for a config file.

# usage: train.py [-h] [--debug] data_config_file data_dir base_dir
python df/train.py path/to/dataset.cfg path/to/data_dir/ path/to/base_dir/

Citation Guide

To reproduce any metrics, we recomend to use the python implementation via pip install deepfilternet.

If you use this framework, please cite: DeepFilterNet: A Low Complexity Speech Enhancement Framework for Full-Band Audio based on Deep Filtering

@inproceedings{schroeter2022deepfilternet,
  title={{DeepFilterNet}: A Low Complexity Speech Enhancement Framework for Full-Band Audio based on Deep Filtering}, 
  author = {Schröter, Hendrik and Escalante-B., Alberto N. and Rosenkranz, Tobias and Maier, Andreas},
  booktitle={ICASSP 2022 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)},
  year={2022},
  organization={IEEE}
}

If you use the DeepFilterNet2 model, please cite: DeepFilterNet2: Towards Real-Time Speech Enhancement on Embedded Devices for Full-Band Audio

@inproceedings{schroeter2022deepfilternet2,
  title = {{DeepFilterNet2}: Towards Real-Time Speech Enhancement on Embedded Devices for Full-Band Audio},
  author = {Schröter, Hendrik and Escalante-B., Alberto N. and Rosenkranz, Tobias and Maier, Andreas},
  booktitle={17th International Workshop on Acoustic Signal Enhancement (IWAENC 2022)},
  year = {2022},
}

If you use the DeepFilterNet3 model, please cite: DeepFilterNet: Perceptually Motivated Real-Time Speech Enhancement

@inproceedings{schroeter2023deepfilternet3,
  title = {{DeepFilterNet}: Perceptually Motivated Real-Time Speech Enhancement},
  author = {Schröter, Hendrik and Rosenkranz, Tobias and Escalante-B., Alberto N. and Maier, Andreas},
  booktitle={INTERSPEECH},
  year = {2023},
}

If you use the multi-frame beamforming algorithms. please cite Deep Multi-Frame Filtering for Hearing Aids

@inproceedings{schroeter2023deep_mf,
  title = {Deep Multi-Frame Filtering for Hearing Aids},
  author = {Schröter, Hendrik and Rosenkranz, Tobias and Escalante-B., Alberto N. and Maier, Andreas},
  booktitle={INTERSPEECH},
  year = {2023},
}

License

DeepFilterNet is free and open source! All code and model weights in this repository are dual-licensed under either:

at your option. This means you can select the license you prefer!

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

DeepFilterNet fork: real-time safe LADSPA noise suppression for PipeWire, KDE tray app DeepFilter Tray, prebuilt plugins, AUR packages (based on Rikorose/DeepFilterNet)

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages