Python Audio Processing: Split Audio File on Silence Using Pydub

In this tutorial, we will use an example to show you how to split an audio file using python pydub library.

Python Audio Proccessing - Split Audio File on Silence Using Pydub

1.Install pydub

pip install pydub

2.Import library

from pydub import AudioSegment
from pydub.silence import split_on_silence

3.Read an audio file

sound_file = AudioSegment.from_wav("audio 1.wav")

4.Start to split audio file

audio_chunks = split_on_silence(sound_file, min_silence_len=500, silence_thresh=-40 )

You should notice:

min_silence_len = 500, means the minimum duration of silence must be a half-second.

5.Output files

for i, chunk in enumerate(audio_chunks):
   out_file = "chunk{0}.wav".format(i)
   print("exporting", out_file)
   chunk.export(out_file, format="wav")