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
muslpy 3.10–3.940 runs
installs and imports cleanly · install 0.0s · import 3.422s · 321.8MB
glibcpy 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.")
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.
fixInstall 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).
fixRename 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.
fixUpdate 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.
fixProcess 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.
fixEnsure 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).