Click removal in audio files with Python
Posted on Tue 23 May 2023 in Audio, Python • Tagged with Audio, Python
A friend of mine had an audio file with many clicks in it. He asked me if I could remove them. I tried with the Audacity click removal tool, but it didn't work: it removed the clicks, but created a lot of artifacts in the audio, so I thought it would be a nice challenge to try to do it with Python.
The waveform looked like this:
I did it using the pydub package. The basic idea is detecting the clicks and replacing them with the previous sample. I used two different criteria to detect the clicks:
-
If the average of the previous samples is below a threshold and the current sample is above another threshold.
-
If the difference between the previous sample and the current one is above a threshold.
The code is not very clean, but it worked. I had to play with the thresholds and the width of the samples to get the best results. I also had to play with the width of the clicks to avoid removing too much audio …
Continue reading