Shell – Remove silence from audio files while leaving gaps

audioffmpegshell-scriptsox

Currently we're using this command within a shell script to remove silence from audio files:

ffmpeg -i $INFILE -af silenceremove=0:0:0:-1:1:${NOISE_TOLERANCE}dB -ac 1 $SILENCED_FILE -y

This works fine except that it removes all the silence, causing the remaining audio to be squeezed together.

How can this be done while leaving two or three seconds between each piece of audio?

The solution needs to be very efficient as we'll be processing a lot of audio and should use a tool that can be fairly easily installed on both Linux and OSX, such as ffmpeg or sox.

Best Answer

The best way that I've seen is by adding the -l flag to silence as follows:

sox in.wav out6.wav silence -l 1 0.1 1% -1 2.0 1%

I've copied this command from Example 6 of this very useful blog post called The Sox of Silence