{"id":6011,"library":"noisereduce","title":"Noise Reduction using Spectral Gating","description":"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.","status":"active","version":"3.0.3","language":"python","source_language":"en","source_url":"https://github.com/timsainb/noisereduce","tags":["audio","signal processing","noise reduction","spectral gating","pytorch","machine learning","sound"],"install":[{"cmd":"pip install noisereduce","lang":"bash","label":"Core library"},{"cmd":"pip install noisereduce[torch]","lang":"bash","label":"With PyTorch backend (optional)"}],"dependencies":[{"reason":"Core numerical operations for audio processing.","package":"numpy"},{"reason":"Scientific computing tools, especially signal processing functions.","package":"scipy"},{"reason":"Progress bar for long-running operations.","package":"tqdm"},{"reason":"Required for the PyTorch-based noise reduction module (noisereduce.nn.NoiseReduce).","package":"torch","optional":true}],"imports":[{"symbol":"reduce_noise","correct":"from noisereduce import reduce_noise"},{"symbol":"NoiseReduce (PyTorch module)","correct":"from noisereduce.nn import NoiseReduce"},{"note":"Only use this import for the legacy (v1.x) API after upgrading to v2.0.0+ if compatibility is required.","wrong":"from noisereduce import reduce_noise","symbol":"reduce_noise (legacy v1)","correct":"from noisereduce.noisereducev1 import reduce_noise"}],"quickstart":{"code":"import noisereduce as nr\nimport numpy as np\n\n# --- 1. Generate dummy noisy audio ---\nrate = 44100  # sampling rate\nduration = 5  # seconds\nt = np.linspace(0, duration, int(rate * duration), endpoint=False)\n\n# Clean signal (e.g., a sine wave)\nclean_audio = 0.5 * np.sin(2 * np.pi * 440 * t) # A4 note\n\n# Add some random noise\nnoise = 0.2 * np.random.randn(len(t))\nnoisy_audio = clean_audio + noise\n\n# --- 2. Reduce noise ---\n# For stationary noise (default and generally faster)\nreduced_noise_stationary = nr.reduce_noise(\n    y=noisy_audio, \n    sr=rate, \n    stationary=True\n)\n\n# For non-stationary noise (e.g., speech with varying background noise)\n# This is often more effective but can be slower.\nreduced_noise_non_stationary = nr.reduce_noise(\n    y=noisy_audio, \n    sr=rate, \n    stationary=False\n)\n\nprint(f\"Original audio shape: {noisy_audio.shape}\")\nprint(f\"Reduced audio (stationary) shape: {reduced_noise_stationary.shape}\")\nprint(f\"Reduced audio (non-stationary) shape: {reduced_noise_non_stationary.shape}\")\n\n# --- Optional: Using the PyTorch backend (requires `pip install noisereduce[torch]`) ---\n# try:\n#     import torch\n#     model = nr.nn.NoiseReduce(sr=rate, nonstationary=False)\n#     audio_tensor = torch.from_numpy(noisy_audio).float().unsqueeze(0) # Add batch dim\n#     reduced_audio_tensor = model(audio_tensor)\n#     reduced_audio_pytorch = reduced_audio_tensor.squeeze(0).numpy()\n#     print(f\"Reduced audio (PyTorch) shape: {reduced_audio_pytorch.shape}\")\n# except ImportError:\n#     print(\"PyTorch not installed, skipping PyTorch example.\")","lang":"python","description":"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."},"warnings":[{"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`.","message":"The 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`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"For performance-critical applications or integration into deep learning pipelines, consider migrating to the `noisereduce.nn.NoiseReduce` module and installing `noisereduce[torch]`.","message":"Version 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`.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=2.0.0"},{"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.","message":"As 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`.","severity":"gotcha","affected_versions":">=3.0.3"}],"env_vars":null,"search_vec":"'3.0.3':44 'activ':48 'advanc':38 'algorithm':21 'audio':15,60 'backend':36 'base':35 'case':40 'current':41 'develop':49 'featur':56 'gate':5,20,66 'implement':28 'improv':59 'introduc':54 'learn':69 'librari':10 'machin':68 'major':52 'new':55 'nois':1,13,63 'noisereduc':6 'numpy/scipy':27 'occasion':51 'offer':23 'perform':32,58 'process':62 'python':9 'pytorch':34,67 'pytorch-bas':33 'reduc':12 'reduct':2,64 'signal':16,61 'sound':70 'spectral':4,19,65 'tradit':26 'updat':53 'use':3,17,39 'version':43","created_at":"2026-04-14T18:38:05.920289+00:00","updated_at":"2026-04-17T14:22:26.965590+00:00","problems":[{"fix":"Install the library using pip: `pip install noisereduce`","cause":"The `noisereduce` library is not installed in the current Python environment or the environment where the code is being run.","error":"ModuleNotFoundError: No module named 'noisereduce'"},{"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(...)`.","cause":"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).","error":"AttributeError: module 'noisereduce' has no attribute 'reduce_noise'"},{"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)`.","cause":"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.","error":"TypeError: reduce_noise() got an unexpected keyword argument 'audio_clip'"},{"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.","cause":"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.","error":"MemoryError: Unable to allocate array with shape (...) and data type float64"},{"fix":"Ensure the sample rate is cast to an integer (e.g., `int(sr_float)`) before passing it to `reduce_noise`.","cause":"The sample rate (`sr`) parameter was provided as a float or another non-integer type instead of an integer.","error":"ValueError: sr must be an integer"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"3.0.3","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/timsainb/noisereduce","docs":null,"changelog":null,"pypi":"https://pypi.org/project/noisereduce/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}