The most recent version of noisereduce comprises two algorithms:
- Stationary Noise Reduction: Keeps the estimated noise threshold at the same level across the whole signal
- Non-stationary Noise Reduction: Continuously updates the estimated noise threshold over time
- The basic intuition is that statistics are calculated on each frequency channel to determine a noise gate. Then the gate is applied to the signal.
- This algorithm is based (but not completely reproducing) on the one outlined by Audacity for the noise reduction effect
- The algorithm takes two inputs:
- A noise clip containing prototypical noise of clip (optional)
- A signal clip containing the signal and the noise intended to be removed
Stationary.noise.reduction.mp4
Stationary.remove.noise.mp4
- A spectrogram is calculated over the noise audio clip
- Statistics are calculated over spectrogram of the the noise (in frequency)
- A threshold is calculated based upon the statistics of the noise (and the desired sensitivity of the algorithm)
- A spectrogram is calculated over the signal
- A mask is determined by comparing the signal spectrogram to the threshold
- The mask is smoothed with a filter over frequency and time
- The mask is appled to the spectrogram of the signal, and is inverted If the noise signal is not provided, the algorithm will treat the signal as the noise clip, which tends to work pretty well
- The non-stationary noise reduction algorithm is an extension of the stationary noise reduction algorithm, but allowing the noise gate to change over time.
- When you know the timescale that your signal occurs on (e.g. a bird call can be a few hundred milliseconds), you can set your noise threshold based on the assumption that events occuring on longer timescales are noise.
- This algorithm was motivated by a recent method in bioacoustics called Per-Channel Energy Normalization.
Non-stationary.noise.reduction.mp4
Non-stationary.remove.noise.mp4
- A spectrogram is calculated over the signal
- A time-smoothed version of the spectrogram is computed using an IIR filter aplied forward and backward on each frequency channel.
- A mask is computed based on that time-smoothed spectrogram
- The mask is smoothed with a filter over frequency and time
- The mask is appled to the spectrogram of the signal, and is inverted
pip install noisereduce
[Audio Noise Removal And Reduction] (https://colab.research.google.com/github/timsainb/noisereduce/blob/master/notebooks/1.0-test-noise-reduction.ipynb)
from scipy.io import wavfile
import noisereduce as nr
# load data
rate, data = wavfile.read("mywav.wav")
# perform noise reduction
reduced_noise = nr.reduce_noise(y=data, sr=rate)
wavfile.write("mywav_reduced_noise.wav", rate, reduced_noise)