Last modified: Apr 16, 2026 By Alexander Williams

Denoise Audio with Python: A Clear Guide

Noise ruins audio. Hiss, hum, and background sounds distract listeners. Cleaning audio is essential for podcasts, music, and voice recordings. Python makes this task easy and accessible.

This guide will show you how to denoise audio files. We will use powerful libraries and simple code. You will learn practical methods to improve your sound quality.

Why Denoise Audio?

Clean audio is professional audio. Noise reduction has many uses. Podcasters need clear speech. Musicians want clean recordings. Researchers analyze sound without interference.

Common noise types include constant hum, random hiss, and sudden clicks. Python can target and remove these sounds. It automates a process that was once complex and manual.

For a broader look at handling sound, see our Python Audio Processing Guide for Beginners.

Essential Python Audio Libraries

You need specific tools to work with audio in Python. These libraries handle reading, writing, and processing sound files.

Librosa is the foundation for audio analysis. It loads audio into numerical arrays. This lets Python manipulate the sound data mathematically.

NumPy works with these arrays. It performs fast calculations. This is crucial for processing large audio files efficiently.

SoundFile or pydub are used for reading and writing WAV or MP3 files. They bridge the gap between audio files and Python data.

To explore all your options, check out our detailed resource on Python Audio Libraries: Play, Record, Process.

Installing Required Libraries

First, install the necessary packages. Use pip, the Python package installer. Open your terminal or command prompt.


pip install librosa numpy soundfile noisereduce
    

This command installs four key libraries. Librosa and NumPy are for core processing. SoundFile handles file input/output. Noisereduce is a dedicated noise reduction tool.

Method 1: Spectral Gating with noisereduce

Spectral gating is a popular technique. It assumes noise is in the silent parts of your audio. It learns the noise profile and subtracts it.

The noisereduce library implements this well. It is simple and effective for steady noise like fan hum or tape hiss.

Here is a complete example:


import librosa
import soundfile as sf
import noisereduce as nr

# 1. Load the noisy audio file
audio_path = 'noisy_recording.wav'
audio_data, sample_rate = librosa.load(audio_path, sr=None)

# 2. Select a segment of noise (e.g., first 2 seconds of silence)
noise_sample = audio_data[:2 * sample_rate]

# 3. Perform noise reduction
reduced_noise_audio = nr.reduce_noise(y=audio_data, sr=sample_rate, y_noise=noise_sample, prop_decrease=0.9)

# 4. Save the cleaned audio to a new file
output_path = 'cleaned_audio.wav'
sf.write(output_path, reduced_noise_audio, sample_rate)

print(f"Audio denoised and saved to: {output_path}")
    

Let's break down the code. The librosa.load() function reads the audio file. It returns the data and the sample rate.

We extract a noise sample from the first two seconds. This should be a period where only the background noise is present.

The nr.reduce_noise() function is the core. It uses the noise sample to clean the entire audio. The prop_decrease argument controls reduction strength (0.9 = 90%).

Finally, sf.write() saves the clean audio as a new WAV file.

Method 2: Using a Spectral Subtraction Filter

Another approach is spectral subtraction. This method estimates the noise in the frequency domain. It then subtracts this estimate from the signal.

We can implement a basic version using Librosa and NumPy. This gives you more control over the process.


import librosa
import numpy as np
import soundfile as sf

def spectral_subtraction(audio, sr, noise_start=0, noise_end=2):
    """
    A simple spectral subtraction denoiser.
    """
    # Convert to spectrogram (time-frequency representation)
    stft = librosa.stft(audio)
    magnitude = np.abs(stft)
    phase = np.exp(1.j * np.angle(stft))

    # Estimate noise spectrum from a silent segment
    noise_segment = audio[noise_start*sr:noise_end*sr]
    stft_noise = librosa.stft(noise_segment)
    magnitude_noise = np.abs(stft_noise).mean(axis=1, keepdims=True)

    # Subtract noise estimate, ensure non-negative values
    magnitude_clean = magnitude - magnitude_noise
    magnitude_clean = np.maximum(magnitude_clean, 0)

    # Reconstruct the audio signal
    clean_stft = magnitude_clean * phase
    clean_audio = librosa.istft(clean_stft)

    return clean_audio

# Load audio
audio_data, sample_rate = librosa.load('noisy_voice.wav', sr=None)

# Apply the denoising function
denoised_audio = spectral_subtraction(audio_data, sample_rate, noise_start=0, noise_end=1)

# Save result
sf.write('voice_cleaned_spectral.wav', denoised_audio, sample_rate)
print("Spectral subtraction complete.")
    

This code defines a custom function. librosa.stft() converts audio to a spectrogram. The spectrogram shows how frequencies change over time.

We calculate the average noise magnitude from a quiet segment. We subtract this from the full signal's magnitude.

The np.maximum() function ensures values don't go below zero. Finally, librosa.istft() converts the clean spectrogram back to audio.

Tips for Effective Audio Denoising

Good results depend on good practices. Follow these tips for the best outcome.

Get a clean noise profile. Use a segment with only background noise. The first few seconds of a recording often work well.

Avoid over-processing. Setting reduction too high can cause artifacts. Your audio may sound robotic or watery. Start with a prop_decrease of 0.7 to 0.8.

Pre-process your audio. Normalize volume before denoising. This helps the algorithm distinguish signal from noise more clearly.

Experiment with parameters. Different noises need different approaches. Try both methods shown here on your specific audio file.

Conclusion

Denoising audio with Python is powerful and straightforward. Libraries like noisereduce and Librosa do the heavy lifting. You can remove hum, hiss, and other unwanted sounds.

Start with the spectral gating method for simplicity. Use the spectral subtraction approach for more control. Always listen to your results to find the right balance.

Clean audio improves any project. Use this guide to make your recordings sound professional. Happy coding and clear listening!