Ubuntu – How to split an mp3 file by detecting silent parts

audio recordingffmpegmp3

I have a big mp3 file including more songs. Is there any way to split the file by detecting silent parts? I would prefer a command line tool (e.g. ffmpeg).

Tried:

youtube-dl –ignore-errors –format bestaudio –extract-audio –audio-format mp3 –audio-quality 160K –output "%(title)s.%(ext)s" –yes-playlist

Best Answer

You will likely not get a ready-to-go solution but will need to create a script yourself. pydub is made for this (it uses ffmpeg or libav internally) and it has a functions called split_on_silence() with some settings like keep_silence=100.

Some references from stackoverflow that have examples: 37725416 and 45526996 And from the creator of pydub.

From the 1st link the interesting part:

# Load your audio.
song = AudioSegment.from_mp3("your_audio.mp3")

chunks = split_on_silence (
   # Use the loaded audio. 
   song, 
   # Specify that a silent chunk must be at least 2 seconds or 2000 ms long.
   min_silence_len = 2000,
   # Consider a chunk silent if it's quieter than -16 dBFS.
   # (You may want to adjust this parameter.)
   silence_thresh = -16
)