This project has moved. For the latest updates, please go here.

Silence Detection

Sep 9, 2009 at 9:16 PM

I would like to compress the audio stream I'm recording to remove long "silent" sections.  Since there will always be some level of background noise, I'm not sure how to properly detect silence.  Does anyone know of a good algorithm that works well within the context of NAudio, or better yet example code?



Sep 11, 2009 at 9:22 AM

search the internet for code for a "noise gate". the simplest ones just have a threshold level below which is considered silence.

Sep 20, 2009 at 10:29 PM

It is actually fairly simple, assuming your wave file is well behaved (not offset).

naudio treats the wave as a 16 bit signed number, so you can set a threshold of say 0.05* int.max and 0.05 int.min. To avoid spiky recordings, clicks and pops, read several samples and average them (see the WaveViewer for example code). Then if the wave stays below the threshold you have silence.