Skip to main content

Blind SNR estimation using DeepFilterNet. Includes bundled model weights.

Project description

mashood-neural-snr 🎧

PyPI version License: MIT Downloads

A Robust Blind SNR Estimator for Single-Channel Audio using Deep Learning.

mashood-neural-snr solves the "Cocktail Party Problem" for SNR estimation. It uses Neural Source Separation (DeepFilterNet) to mathematically isolate speech from noise, allowing for accurate signal-to-noise ratio calculation even when noise overlaps with speech.


🚀 Quick Start

Installation

pip install mashood-neural-snr

Usage

from neural_snr import snr

# Returns SNR in Decibels (dB)
score = snr("path/to/my_audio.wav")

print(f"Estimated SNR: {score:.2f} dB")

1. Problem Definition: The Challenge of Mixed Signals

In a "Blind" analysis scenario, the objective is to calculate the Signal-to-Noise Ratio (SNR) of a recording where clean speech and background noise are already mixed. Access to the discrete ground-truth files (Clean Speech and Isolated Noise) is unavailable.

1.1 Limitations of Traditional DSP (VAD)

Conventional Digital Signal Processing approaches, such as Voice Activity Detection (VAD) (e.g., WADA-SNR, NIST STNR), rely on a binary segmentation strategy. These algorithms identify "Silence" segments to estimate the noise floor and assume this noise level remains constant under the speech.

The "Overlap" Failure Mode:

This approach fails in real-world acoustic environments due to the Signal Overlap Problem.

  • Dynamic Noise: If a transient noise source (e.g., a siren, a car passing, or a door slamming) occurs simultaneously with the speech, a VAD algorithm cannot isolate it.
  • Result: The algorithm classifies the loud noise as "Speech Energy." Consequently, the noise power is under-estimated, and the signal power is over-estimated, leading to a falsely inflated SNR calculation.

2. The Solution: Neural Source Separation

To address the limitations of VAD, this methodology employs DeepFilterNet, a state-of-the-art speech enhancement model, as a semantic source separator.

Unlike traditional filters that rely on frequency gating, DeepFilterNet acts as a Non-Linear Semantic Filter. Trained on massive datasets of human speech, the model learns to identify the harmonic structure of the voice. It can effectively separate speech from background noise even when they overlap completely in both time and frequency domains.


3. Methodology: "Reverse-Engineering" the Noise

The core concept relies on isolating the speech component to mathematically derive the noise profile via subtraction.

3.1 The Mathematical Workflow

The audio signal is modeled as an additive mixture:

$$y(t) = s(t) + n(t)$$

(Where $y$ is mixture, $s$ is speech, $n$ is noise)

Step 1: Inference (Speech Estimation)

The noisy mixture is processed through the DeepFilterNet model to generate an estimated clean signal.

$$s_{est} = \text{Model}(y)$$

Step 2: Residual Extraction

Since the mixture is the sum of its parts, the noise profile can be derived by subtracting the estimated speech from the original mixture.

$$n_{est} = y - s_{est}$$

Step 3: SNR Calculation

The SNR is computed by comparing the average power (Mean Squared Error) of the separated components.

$$SNR_{dB} = 10 \cdot \log_{10}\left(\frac{P_{s_est}}{P_{n_est}}\right)$$


4. Engineering Constraints & Correction

Direct subtraction fails due to Neural Network Latency and Gain Mismatch. Without correction, the extracted noise profile contains "ghostly" artifacts of the speech. We apply the following corrections:

4.1 Latency Correction (Time Alignment)

Neural networks introduce a processing delay. Direct subtraction of misaligned signals causes phase cancellation errors.

Solution: Cross-Correlation analysis is performed to detect the precise time lag. The estimated speech is then time-shifted to align perfectly with the original mixture.

4.2 Amplitude Scaling (Least Squares Projection)

The model often outputs audio at a normalized volume that differs from the input.

Solution: A scaling factor ($\alpha$) is calculated using Least Squares Projection. This projects the estimated speech onto the mixture to find the optimal volume level that maximizes cancellation.

Corrected Noise Formula:

$$n_{final} = y - (\alpha \cdot s_{aligned})$$


5. Experimental Validation

To quantify robustness, a controlled evaluation was performed using a Standard Speech Dataset (speech mixed with noise at strictly controlled intervals).

5.1 Benchmark Results

Condition Label SNR Avg Est. SNR Abs Error Status
Clean +20 dB 18.76 dB ~1.3 dB
Good +15 dB 14.72 dB 0.7 dB
Fair +10 dB 9.95 dB 0.5 dB
Noisy +5 dB 4.95 dB 0.4 dB
Very Noisy -5 dB -5.10 dB 0.5 dB
Harsh -10 dB -9.83 dB 0.8 dB
Extreme -20 dB -14.24 dB ~6.1 dB ⚠️

5.2 Analysis

1. The High-Precision Zone (+20 dB to -10 dB)

The algorithm performs optimally across this wide range. Because the speech signal maintains enough semantic integrity, the model successfully separates the voice.

  • Observation: The Absolute Error is consistently low, frequently falling below 1.0 dB.
  • Conclusion: Highly reliable for standard environments.

2. The Detection Limit (-20 dB)

The data demonstrates a physical limit at -20 dB.

  • Physical Limitation: At -20 dB, speech energy is submerged so deep below the noise floor that it appears as "Noise Only" to both the human ear and the AI.
  • Failure Mode: The model outputs near-silence for speech, making the ratio calculation mathematically impossible.

6. Conclusion

By utilizing DeepFilterNet to semantically separate speech from noise and applying Cross-Correlation and Least Squares scaling, mashood-neural-snr provides a robust measurement of audio quality.

This approach offers a significant advantage over traditional DSP methods as it accurately accounts for overlapping noise, resulting in a physically consistent measurement.


📄 License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mashood_neural_snr-0.1.2.tar.gz (8.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mashood_neural_snr-0.1.2-py3-none-any.whl (8.0 MB view details)

Uploaded Python 3

File details

Details for the file mashood_neural_snr-0.1.2.tar.gz.

File metadata

  • Download URL: mashood_neural_snr-0.1.2.tar.gz
  • Upload date:
  • Size: 8.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for mashood_neural_snr-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6ffe19fe080734c1d14e5072cd021387a881a9fa7555b4f151ad0359614b102b
MD5 03c77995c6295c1329665947ed2d1024
BLAKE2b-256 fbcb4b05538a8b3ff1c3e2eb312d18c0a738d3a4e2d63ea24379914e6d235fe0

See more details on using hashes here.

File details

Details for the file mashood_neural_snr-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mashood_neural_snr-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2dfb1e68bdc3abdb1a92d3f521f71eabdf75f3770c894fc71a1212f6a7732942
MD5 3a890de883dd125e044ef6d4e48c0de9
BLAKE2b-256 90b411e6f433aadfbcce8d5fdd5fb67598b59612b8ae58e9c6f42cf7814fd489

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page