# Removing background noise algorithm

What is the algorithm for removing background noise from an audio clip of human speech? Say I have a 10 second audio clip of somebody talking, and there is background noise of them tapping on their keyboard. Now, I would like to remove the "keyboard tapping" signal while preserving the speech signal (always assuming a single speaker).

What are the necessary steps to achieve this? Is the best approach to use voice activity detection to try and isolate a representative signal of keyboard tapping, and then "remove" that pattern from the rest of the signal? What is required to "remove" the specific sound from the signal once identified?

• should this be a fully automated process? Is the nature of the noise known in advance (e.g keyboard tapping) or could be anything? – dsp_user Apr 7 '20 at 5:55
• The process does not necessarily have to be fully automatic. Sure, assume that the nature of the noise is known in advance. – Harry Stuart Apr 7 '20 at 5:59

In order to remove the noise from the signal, you need to subtract the spectral content of the noise from that of the signal ( filtered_signal = unfiltered_signal - noise ). This technique is called spectral subtraction. This will only work well if the noise is rather uniform across the entire length of the signal.

The steps required to do this are

1. Identify the noise region(s) in your signal and do an FFT on it. A single noise region is enough provided that it's long enough for your FFT.

2. Do the FFT on the entire signal. This may be done in multiple segments (frames).

3. In the frequency domain, subtract the result of step 1 from step 2. If you're using multiple segments in step 2, then simply subtract the result from step 1 from every segment. This will effectively filter your signal.

4. Do an inverse fft, which will bring your signal back into the time domain.

Note that I said that this technique will only work if the noise is uniform and by uniform I mean that its spectral content is rather constant. But you can also have regions in your audio where the noise is not present at all so obviously trying to remove the noise from these noiseless regions should be avoided. If your noise removal process is manual (at least in part), it would be possible (albeit tedious) to label such regions and then have the algorithm skip them.

• Thanks for the answer! Just quickly, what if the noise is not uniform? Are you able to point to any techniques for such a case? – Harry Stuart Apr 7 '20 at 6:51
• The technique described in my answer can still be used provided that you accurately identify regions having different noise profiles so that you can subtract the correct noise profiles from their corresponding signal segments. Granted, this is much more involved and not always applicable. – dsp_user Apr 7 '20 at 7:00