Search code examples
audiosox

Detecting and printing timestamps of periods of silence using SoX


I am trying to output the begin-timestamps of periods of silence (since there is background noise, by silence I mean a threshold) in a given audio file. Eventually, I want to split the audio file into smaller audio files, given these timestamps. It is important that no part of the original file be discarded.

I tried

sox in.wav out.wav silence 1 0.5 1% 1 2.0 1% : newfile : restart

(courtesy http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/)

Although, it somewhat did the job, it also trimmed and discarded the periods of silence, which I do not want happening.

Is 'silence' the right option, or is there a simpler way to accomplish what I need to do?

Thanks.


Solution

  • Unfortunately not Sox, but ffmpeg has a silencedetect filter that does exactly what you're looking for:

    ffmpeg -i in.wav -af silencedetect=noise=-50dB:d=1 -f null -
    

    (detecting threshold of -50db, for a minimum of 1 seconds, cribbed from the ffmpeg documentation)

    ...this would print a result like this:

    Press [q] to stop, [?] for help
    [silencedetect @ 0x7ff2ba5168a0] silence_start: 264.718
    [silencedetect @ 0x7ff2ba5168a0] silence_end: 265.744 | silence_duration: 1.02612
    size=N/A time=00:04:29.53 bitrate=N/A