Registry / ai-ml / noisereduce

noisereduce

JSON →
library3.0.3pypypi✓ verified 91d ago

NoiseReduce is a Python library for reducing noise in audio signals using a spectral gating algorithm. It offers both a traditional NumPy/SciPy implementation and a more performant PyTorch-based backend for advanced use cases. Currently at version 3.0.3, it is under active development with occasional major updates introducing new features and performance improvements.

pip install noisereduce
INSTALL
IMPORT
SIG · NOISEREDUCE
N
noisereduce
ai-mlpythonv3.0.3
Install
11.3s avg
Import
3334ms
Disk
325MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.940 runs
installs and imports cleanly · install 0.0s · import 3.422s · 321.8MB
glibc
py 3.10–3.940 runs
installs and imports cleanly · install 11.3s · import 3.247s · 309MB
325MB installed
● package 325MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

reduce_noise
✓ from noisereduce import reduce_noise
NoiseReduce (PyTorch module)
✓ from noisereduce.nn import NoiseReduce
reduce_noise (legacy v1)
✓ from noisereduce.noisereducev1 import reduce_noise
✗ from noisereduce import reduce_noise
Only use this import for the legacy (v1.x) API after upgrading to v2.0.0+ if compatibility is required.

This quickstart demonstrates how to generate a simple noisy audio signal and apply noise reduction using both the default stationary and the more robust non-stationary modes of the `noisereduce.reduce_noise` function. It also includes comments on how to use the optional PyTorch backend for higher performance.

import noisereduce as nr import numpy as np # --- 1. Generate dummy noisy audio --- rate = 44100 # sampling rate duration = 5 # seconds t = np.linspace(0, duration, int(rate * duration), endpoint=False) # Clean signal (e.g., a sine wave) clean_audio = 0.5 * np.sin(2 * np.pi * 440 * t) # A4 note # Add some random noise noise = 0.2 * np.random.randn(len(t)) noisy_audio = clean_audio + noise # --- 2. Reduce noise --- # For stationary noise (default and generally faster) reduced_noise_stationary = nr.reduce_noise( y=noisy_audio, sr=rate, stationary=True ) # For non-stationary noise (e.g., speech with varying background noise) # This is often more effective but can be slower. reduced_noise_non_stationary = nr.reduce_noise( y=noisy_audio, sr=rate, stationary=False ) print(f"Original audio shape: {noisy_audio.shape}") print(f"Reduced audio (stationary) shape: {reduced_noise_stationary.shape}") print(f"Reduced audio (non-stationary) shape: {reduced_noise_non_stationary.shape}") # --- Optional: Using the PyTorch backend (requires `pip install noisereduce[torch]`) --- # try: # import torch # model = nr.nn.NoiseReduce(sr=rate, nonstationary=False) # audio_tensor = torch.from_numpy(noisy_audio).float().unsqueeze(0) # Add batch dim # reduced_audio_tensor = model(audio_tensor) # reduced_audio_pytorch = reduced_audio_tensor.squeeze(0).numpy() # print(f"Reduced audio (PyTorch) shape: {reduced_audio_pytorch.shape}") # except ImportError: # print("PyTorch not installed, skipping PyTorch example.")
Debug
Known issues
breakingThe API for `noisereduce` underwent a significant breaking change in version 2.0.0. The primary `reduce_noise` function's signature and behavior changed, and the old API was moved to `noisereduce.noisereducev1.reduce_noise`.
fix
Update your code to use the new `noisereduce.reduce_noise` function. If you need to maintain compatibility with older code, import `reduce_noise` from `noisereduce.noisereducev1`.
affects: >=2.0.0
breakingVersion 3.0.0 introduced a new PyTorch-based implementation for `noisereduce`, offering significant performance improvements and the ability to integrate into neural network architectures. While the original `reduce_noise` function still exists, new PyTorch-specific functionality requires `noisereduce.nn.NoiseReduce`.
fix
For performance-critical applications or integration into deep learning pipelines, consider migrating to the `noisereduce.nn.NoiseReduce` module and installing `noisereduce[torch]`.
affects: >=3.0.0
gotchaThe `stationary` parameter in `nr.reduce_noise` (default: `True`) significantly impacts results. While `True` works well for constant background hums, `False` is crucial for non-stationary noise sources like speech or music, though it can be computationally more intensive.
fix
Experiment with `stationary=True` and `stationary=False` based on the characteristics of your noise. For voice or complex environmental sounds, `stationary=False` is generally recommended.
affects: >=2.0.0
gotchaAs of version 3.0.3, `librosa` is no longer a direct dependency of `noisereduce`. If your existing code relies on `librosa` for audio loading, resampling, or other utilities in conjunction with `noisereduce`, you will need to explicitly install `librosa`.
fix
If your project requires `librosa`, ensure it is explicitly listed in your project's dependencies (e.g., `pip install librosa`). For basic audio file I/O, `soundfile` is a common alternative.
affects: >=3.0.3
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'noisereduce'
The `noisereduce` library is not installed in the current Python environment or the environment where the code is being run.
fix
Install the library using pip: `pip install noisereduce`
AttributeError: module 'noisereduce' has no attribute 'reduce_noise'
This error most commonly occurs when the Python script itself is named `noisereduce.py`, causing Python to import the local script instead of the installed library. It can also occur if attempting to call `reduce_noise` directly on the top-level package after an API change in version 2/3 where the main function became accessible via `noisereduce.reduce_noise` (instead of being nested, or when `create()` is used).
fix
Rename your Python script to something other than `noisereduce.py` (e.g., `my_audio_process.py`). Ensure you are importing and calling the function correctly, typically `import noisereduce as nr` and then `nr.reduce_noise(...)`.
TypeError: reduce_noise() got an unexpected keyword argument 'audio_clip'
The `reduce_noise` function's API changed between older versions and version 2.x/3.x of `noisereduce`. The parameters `audio_clip` and `noise_clip` were replaced by `y` (for the noisy audio) and `y_noise` (for the noise sample), respectively.
fix
Update your code to use the new parameter names `y` and `y_noise`: `reduced_noise = nr.reduce_noise(y=audio_data, sr=sample_rate, y_noise=noise_data)`.
MemoryError: Unable to allocate array with shape (...) and data type float64
This error occurs when processing very large audio files or long audio streams, as `noisereduce` attempts to allocate a large array in memory that exceeds available RAM.
fix
Process the audio in smaller chunks or segments. For example, iterate through the audio, apply noise reduction to each segment, and then concatenate the results. The library also offers a streaming interface for more efficient memory usage in some cases.
ValueError: sr must be an integer
The sample rate (`sr`) parameter was provided as a float or another non-integer type instead of an integer.
fix
Ensure the sample rate is cast to an integer (e.g., `int(sr_float)`) before passing it to `reduce_noise`.
Upgrade
Version history
3.0.3latest on PyPI · released Oct 6, 2024
Audit
Dependencies
numpyrequiredCore numerical operations for audio processing.
scipyrequiredScientific computing tools, especially signal processing functions.
tqdmrequiredProgress bar for long-running operations.
torchoptionalRequired for the PyTorch-based noise reduction module (noisereduce.nn.NoiseReduce).
Agent activity
33 hits · last 30 days
node
30
Resources
noisereduce — pip install noisereduce · libregistry