How to split audio file based on silence

  • Open up terminal
  • Install sox
    • brew install sox
  • sox track03.wav out.wav -V3 silence 1 0.1 1% 1 1.0 1% : newfile : restart

Explanation

track03.wav
This is the input audio file that you want to process.

out.wav
This is the output audio file where the processed audio will be saved.

-V3
This option sets the verbosity level to 3, which provides detailed information about the processing. Higher verbosity levels give more detailed output about the actions SoX is performing.

silence
This is the effect that will be applied to remove silence from the audio.

1 0.1 1%
This part of the command specifies how to trim silence from the beginning of the audio file:

  • 1: Specifies the number of periods of non-silence to wait for before trimming. A value of 1 means it will trim silence until it detects the first period of non-silence.
  • 0.1: Duration in seconds. This indicates that non-silence must last for at least 0.1 seconds to stop trimming.
  • 1%: Silence threshold. Any audio below 1% of the maximum volume level is considered silence.

1 1.0 1%
This part specifies how to trim silence from the end of the audio file:

  • 1: Specifies the number of periods of silence to wait for before stopping trimming. A value of 1 means it will trim audio after detecting the first period of silence.
  • 1.0: Duration in seconds. This indicates that silence must last for at least 1.0 seconds to be trimmed.
  • 1%: Silence threshold. Any audio below 1% of the maximum volume level is considered silence.

: newfile
This tells SoX to create a new output file whenever the silence conditions are met. Each new file will contain audio between periods of silence that meet the specified conditions.

: restart
This tells SoX to restart the silence detection after creating a new file, allowing it to continue processing the rest of the input file and creating additional output files as needed.

BONUS: Do it for all wav files in a folder

for i in *.wav; do sox $i $i -V3 silence 1 0.1 1% 1 1.0 1% : newfile : restart; done