Remove background noise from audio file (python or matlab) I am implementing a project for infant cry detection and the audio set contains background noises. So for preprocessing i need to remove the background noise from the audio.I am not able to get a proper output for the code in jupyter notebook. For this code the output file does not contain anything even the baby cry is erased.

import numpy as np  
import scipy as sp  
from scipy.io.wavfile import read  
from scipy.io.wavfile import write     
from scipy import signal  
import matplotlib.pyplot as plt  
get_ipython().magic('matplotlib inline')  

(Frequency, array) = read('cry.wav')  

len(array)  

plt.plot(array)   
plt.title('Original Signal Spectrum')  
plt.xlabel('Frequency(Hz)')  
plt.ylabel('Amplitude')  

FourierTransformation = sp.fft(array)  

scale = sp.linspace(0, Frequency, len(array))  

plt.stem(scale[0:5000], np.abs(FourierTransformation[0:5000]), 'r')    
plt.title('Signal spectrum after FFT')  
plt.xlabel('Frequency(Hz)')  
plt.ylabel('Amplitude')  


GuassianNoise = np.random.rand(len(FourierTransformation))  


NewSound = GuassianNoise + array  

write("New-Sound-Added-With-Guassian-Noise.wav", Frequency, NewSound)  

b,a = signal.butter(5, 1000/(Frequency/2), btype='highpass')  

filteredSignal = signal.lfilter(b,a,NewSound)  
plt.plot(filteredSignal) # plotting the signal.  
plt.title('Highpass Filter')  
plt.xlabel('Frequency(Hz)')  
plt.ylabel('Amplitude')  


c,d = signal.butter(5, 380/(Frequency/2), btype='lowpass') # ButterWorth low-filter  
newFilteredSignal = signal.lfilter(c,d,filteredSignal) # Applying the filter to the signal  
plt.plot(newFilteredSignal) # plotting the signal.  
plt.title('Lowpass Filter')  
plt.xlabel('Frequency(Hz)')  
plt.ylabel('Amplitude')  

write("New-Filtered-Sound.wav", Frequency, newFilteredSignal)  



Can i know how to debug this code or get any other code.
Since you're adding white noise, the highpass and lowpass filtering will almost  not remove the noise in the frequency band where you want to keep your signal, so you will always have some background noise with this highpass and lowpass filtering strategy.

Not sure if this helps, it depends on the signal-to-noise ratio:
If you can clearly distinguish the noise from the signal in the spectrum (something similar as in the second figure of the Noisy Signal example in Matlab's documentation of the fft), you could set a threshold and make the spectrum with an amplitude below that threshold equal to zero before taking an inverse Fourier transform to get back to the (denoised) time-domain signal.

By the way, GuassianNoise = np.random.rand(len(FourierTransformation)) produces uniformly distributed noise. To get Gaussian noise, you need randn instead of rand.