MENU

[AI from Scratch] Episode 307: Noise Reduction — Techniques for Removing Noise from Audio Data

TOC

Recap and Today’s Theme

Hello! In the previous episode, we discussed Mel-Frequency Cepstral Coefficients (MFCC), a crucial tool for extracting features from audio data used in speech recognition and acoustic analysis.

Today, we’ll focus on noise reduction, an essential process to improve the quality of audio data by removing unwanted sounds or background noise. By doing so, we can enhance clarity, making it easier to analyze or recognize speech accurately. This episode will introduce the fundamental techniques for noise reduction and show you how to implement them using Python.

Basics of Noise Reduction

Audio data often contains various types of noise, and properly addressing these noises can significantly improve the quality of sound. The most common types of noise include:

  • White Noise: Noise that has equal energy distribution across all frequencies.
  • Background Noise: Environmental noises such as wind, human chatter, or machine sounds.
  • Hum Noise: Low-frequency noise caused by electrical interference (e.g., 50Hz or 60Hz hum from power lines).

To remove these types of noise, several approaches are commonly used:

Noise Reduction Methods

  1. Spectral Subtraction:
  • This technique reduces noise by subtracting the noise spectrum from the signal’s spectrum. It works by analyzing the noise during quiet portions of the signal and suppressing that pattern throughout the audio.
  1. Bandpass Filtering:
  • Uses filters that allow specific frequency ranges to pass through while reducing unwanted frequencies. For instance, high-pass filters and low-pass filters can suppress low- and high-frequency noise, respectively.
  1. Wavelet Transform:
  • Decomposes the audio signal into different scales or frequency bands and removes noise from each band. This is particularly effective for irregular noises.
  1. Autoencoders and Deep Learning:
  • Recently, deep learning techniques like autoencoders have been used to separate speech from noise by training models to differentiate between clean and noisy signals.

Noise Reduction with Python and LibROSA

In this section, we will demonstrate how to perform noise reduction using Python. We will use the LibROSA library to load the audio data and the noisereduce library for noise reduction.

1. Installing Required Libraries

First, install LibROSA and noisereduce:

pip install librosa noisereduce

The noisereduce library implements noise reduction using the spectral subtraction method.

2. Loading the Audio Data

Let’s begin by loading the audio file using LibROSA:

import librosa

# Load the noisy audio file
audio_path = 'noisy_audio.wav'
y, sr = librosa.load(audio_path, sr=None)

# Check the audio length and sampling rate
print(f'Audio length: {len(y)} samples, Sampling rate: {sr} Hz')

This code reads the audio file and returns the waveform (y) and the sampling rate (sr).

3. Performing Noise Reduction

Now, let’s apply noise reduction using noisereduce:

import noisereduce as nr
import matplotlib.pyplot as plt

# Apply noise reduction
reduced_noise = nr.reduce_noise(y=y, sr=sr)

# Plot the original and denoised waveforms
plt.figure(figsize=(10, 4))
plt.plot(y, label='Original')
plt.plot(reduced_noise, label='Denoised', alpha=0.75)
plt.legend()
plt.title('Waveform before and after Noise Reduction')
plt.xlabel('Samples')
plt.ylabel('Amplitude')
plt.show()
  • nr.reduce_noise(y, sr): Reduces noise from the audio data using spectral subtraction.
  • The graph shows the waveform before and after noise reduction, allowing you to visualize the effect of the noise removal.

4. Adjusting Noise Reduction Parameters

The noisereduce library allows you to adjust the parameters based on the type of noise:

reduced_noise = nr.reduce_noise(y=y, sr=sr, prop_decrease=0.8, stationary=True)
  • prop_decrease: Controls the amount of noise reduction. Increasing the value (e.g., 0.8) reduces more noise but may also affect the audio quality.
  • stationary: If set to True, assumes that the noise is consistent (e.g., white noise). For dynamic noise, set it to False to handle varying noise levels.

5. Saving and Playing the Cleaned Audio

After noise reduction, you can save the cleaned audio and listen to it:

import soundfile as sf

# Save the denoised audio
sf.write('cleaned_audio.wav', reduced_noise, sr)

# Play the cleaned audio in Jupyter Notebook
from IPython.display import Audio
Audio('cleaned_audio.wav')

This saves the cleaned audio to a new file and allows you to play it back.

Applications and Considerations for Noise Reduction

When applying noise reduction, it’s important to choose the appropriate technique and parameters based on the nature of the noise and the desired result. Here are some application examples and considerations:

Applications

  • Podcasts and Recorded Speech: Removing background noise to make the speaker’s voice clearer.
  • Conference Calls and Interviews: Cleaning up recordings to remove environmental noise, such as wind or machine hum.
  • Music Production: Reducing hum or white noise in instrument or vocal recordings.

Considerations

  1. Over-Reduction Risk:
  • Reducing too much noise can degrade the quality of the audio, sometimes removing important parts of the signal or introducing artifacts like echo. Carefully adjust the noise reduction parameters to avoid these issues.
  1. Handling Different Types of Noise:
  • Different types of noise may require different approaches. For example, low-frequency hum can be addressed with a band-stop filter, while irregular noise may benefit from wavelet transforms.

Summary

In this episode, we discussed noise reduction techniques for improving the quality of audio data. Using Python’s LibROSA and noisereduce libraries, we demonstrated how to effectively remove noise and enhance the clarity of audio recordings. Noise reduction is essential in various fields, from podcast editing to music production and speech recognition.

Next Episode Preview

In the next episode, we’ll explore audio preprocessing techniques, including normalization and filtering. These techniques further improve the quality of audio data and enhance recognition and analysis accuracy.


Notes

  • Spectral Subtraction: A method that removes noise by subtracting the noise’s spectral components from the audio signal.
  • Bandpass Filter: A filter that passes frequencies within a certain range and attenuates frequencies outside that range.
Let's share this post !

Author of this article

株式会社PROMPTは生成AIに関する様々な情報を発信しています。
記事にしてほしいテーマや調べてほしいテーマがあればお問合せフォームからご連絡ください。
---
PROMPT Inc. provides a variety of information related to generative AI.
If there is a topic you would like us to write an article about or research, please contact us using the inquiry form.

Comments

To comment

TOC