1

I need to find a silence in a mp3 file. Simple as that.

For example:

  • Find a silence GREATER than X seconds in "file.mp3", then send an errorcode 0 if X seconds of silence found, or errorcode 1 if not found the silence.

I can try it in Batch, VBS, Ruby or Python (Cause I have all to practice, but I only know Batch). I have no idea of music libs and that things...

No matter if I need 3rd party software to do that job like CommandLine APPS...

Note: The silence can be in the middle of the mp3 file too. For example in the files called "Hidden tracks" that is: 1 song + 1 large silence of minutes + another song (All in only 1 mp3 file) So I need something to search X selince into the entire file, Not only near the end of the file...

Note 2: I need to do it in Windows.

Any ideas please?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 1
    Convert the MP3 audio data to raw PCM, scan through the samples looking for chunks that are below whatever threshold you want. – Brad Jun 17 '12 at 20:12

2 Answers2

5

use sox and it's silence filter

checking output of sox $infile -n stat and sox $infile -n silence 1 0.1 1% -1 0.1 1% stat and comparing the lengths of original and trimmed file should do the trick

qdiesel
  • 401
  • 3
  • 9
  • thanks this is great, i have only a question: (i'm in windows) i get this error when i try to use the "-n stat" command: sox FAIL util: Unable to load MAD decoder library (libmad). – ElektroStudios Jun 17 '12 at 20:53
  • yes thankyou again i downloaded the sox compiled with libmad and lame... i have a file with 5 seconds of silence (i mean no audio peaks), when i try the second command i get NOTHING: "sox test.mp3 -n silence 1 0.1 1% -1 0.1 1%" 'im doing something wrong? And the periods are ms or seconds? and sorry for my ignorance but sure this can used to only "find" silence? cause i readed the documentation and only says is to write or delete silence... :-/ ty for all – ElektroStudios Jun 17 '12 at 21:05
  • you forgot `stat` at the end of the command. periods are in seconds if fractional and in samples otherwise. `-n` flag tells sox to discard any audio processed. – qdiesel Jun 17 '12 at 21:14
4

Do this:

  • decode mp3 with some mp3 decoding library, you will get PCM out of it.
  • PCM data is one short after another, which means 16 bit signed numbers
  • you will have to find consecutive amount of shorts which are smaller in absolute to a some small value, say 100 (range is 32767)
  • length of the number of shorts is determined by: your desired silence duration, number of channels in the file, frequency of the sampling
  • if you have this number of shorts that are smaller, you have your silence.

Please use comments to add questions to the areas that you need more information with, or add new questions for that, since there are many steps to the task and I guess that all of them will make this one question too specific.

Daniel Mošmondor
  • 19,718
  • 12
  • 58
  • 99