Blind SNR estimation using DeepFilterNet. Includes bundled model weights.
Project description
mashood-neural-snr 🎧
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mashood_neural_snr-0.1.4.tar.gz.
File metadata
- Download URL: mashood_neural_snr-0.1.4.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4380be39a793e1f36636c644492f47e007690616104ddb97bb032600c5192e52
|
|
| MD5 |
677d8c214fa05eaa5f9ed5d1e870ffe0
|
|
| BLAKE2b-256 |
d82a26957083b54d2395db4a9541d0ad6adb28b68ee0fdc1ba1ee2c1e46e044a
|
File details
Details for the file mashood_neural_snr-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mashood_neural_snr-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32c5af6e08cd003cf65f304b60ce6187e104e54765df75cc3dab91eed9dc66d5
|
|
| MD5 |
5f2d385372012bdfba19c90d103ddd05
|
|
| BLAKE2b-256 |
ce277c673a0ae4d7dd122bfe9386c01cdb7a6e9e4dd056556eb4ef16626c5076
|