692d1131c0f77f85a9068f22ae5e7bf26352a0b2,examples/noise_reduction_spectral_subtraction.py,,,#,29
Before Change
signal_norm = signal / np.abs(signal).max()
min_val = -80
max_val = -40
plt.figure()
plt.subplot(3, 1, 1)
plt.specgram(noisy_signal[:n-hop], NFFT=256, Fs=fs_s, vmin=min_val, vmax=max_val)
plt.title("Noisy Signal")
plt.subplot(3, 1, 2)
plt.specgram(processed_audio[hop:n], NFFT=256, Fs=fs_s, vmin=min_val, vmax=max_val)
plt.title("Denoised Signal")
plt.subplot(3, 1, 3)
After Change
beta = 30 // An overestimation factor to "push" the suppression towards db_reduc.
alpha = 7 // An exponential factor to tune the suppresion (see documentation of "SpectralSub").
plot_spec = True
Prepare input file
fs_s, signal = wavfile.read(os.path.join(os.path.dirname(__file__),
"input_samples",
"cmu_arctic_us_aew_a0001.wav"))
fs_n, noise = wavfile.read(os.path.join(os.path.dirname(__file__),
"input_samples",
"doing_the_dishes.wav"))
if fs_s != fs_n:
raise ValueError("Signal and noise WAV files should have same sampling "
"rate for this example.")
// truncate to same length
if len(noise) < len(signal):
raise ValueError("Length of signal file should be longer than noise "
"file for this example.")
noise = noise[:len(signal)]
// weight noise according to desired SNR
signal_level = np.linalg.norm(signal)
noise_level = np.linalg.norm(noise)
noise_fact = signal_level / 10**(snr/20)
noise_weighted = noise*noise_fact/noise_level
// add signal and noise
noisy_signal = signal + noise_weighted
noisy_signal /= np.abs(noisy_signal).max()
noisy_signal -= noisy_signal.mean()
wavfile.write(os.path.join(os.path.dirname(__file__), "output_samples",
"denoise_input.wav"), fs_s,
noisy_signal.astype(np.float32))
Create STFT and SCNR objects
hop = nfft // 2
window = pra.hann(nfft, flag="asymmetric", length="full")
stft = pra.transform.STFT(nfft, hop=hop, analysis_window=window,
streaming=True)
scnr = SpectralSub(nfft, db_reduc, lookback, beta, alpha)
lookback_time = hop/fs_s * lookback
print("Lookback : %f seconds" % lookback_time)
Process as in real-time
// collect the processed blocks
processed_audio = np.zeros(signal.shape)
n = 0
while noisy_signal.shape[0] - n >= hop:
// SCNR in frequency domain
stft.analysis(noisy_signal[n:(n+hop), ])
gain_filt = scnr.compute_gain_filter(stft.X)
// back to time domain
processed_audio[n:n+hop, ] = stft.synthesis(gain_filt*stft.X)
// update step
n += hop
Save and plot spectrogram
wavfile.write(os.path.join(os.path.dirname(__file__),
"output_samples",
"denoise_output_SpectralSub.wav"), fs_s,
pra.normalize(processed_audio).astype(np.float32))
print("Noisy and denoised file written to: "%s"" %
os.path.join(os.path.dirname(__file__), "output_samples"))
signal_norm = signal / np.abs(signal).max()
if plot_spec:
min_val = -80
max_val = -40
plt.figure()
plt.subplot(3, 1, 1)
plt.specgram(noisy_signal[:n-hop], NFFT=256, Fs=fs_s,
vmin=min_val, vmax=max_val)
plt.title("Noisy Signal")
plt.subplot(3, 1, 2)
plt.specgram(processed_audio[hop:n], NFFT=256, Fs=fs_s,
vmin=min_val, vmax=max_val)
plt.title("Denoised Signal")
plt.subplot(3, 1, 3)
plt.specgram(signal_norm[:n-hop], NFFT=256, Fs=fs_s,
vmin=min_val, vmax=max_val)
plt.title("Original Signal")
plt.tight_layout(pad=0.5)
plt.show()

In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 7
Instances
Project Name: LCAV/pyroomacoustics
Commit Name: 692d1131c0f77f85a9068f22ae5e7bf26352a0b2
Time: 2019-01-08
Author: ebezzam@gmail.com
File Name: examples/noise_reduction_spectral_subtraction.py
Class Name:
Method Name:
Project Name: LCAV/pyroomacoustics
Commit Name: 692d1131c0f77f85a9068f22ae5e7bf26352a0b2
Time: 2019-01-08
Author: ebezzam@gmail.com
File Name: examples/noise_reduction_spectral_subtraction.py
Class Name:
Method Name: