kas
kas

Reputation: 149

C#, How to decide whether an audio file is "silent" in a specific time period of its running?

basically, im looking for a way to simply input a mp3 file name , start time , end time and maybe a threshold value (as "silence" could be a relative term ?) and get the output on whether the mp3 file is silent or not within that input time period.

public static bool IsSilent(string audioFilePath, TimeSpan startTime , TimeSpan endTime, int? threshold) 
{
        //how to implement ? 
}

any code or guidance is appreciated.

Upvotes: 1

Views: 456

Answers (1)

Mark Heath
Mark Heath

Reputation: 49482

The simplest approach is to use an AudioFileReader to get an ISampleProvider allowing you to examine each sample as a floating point number in the range -1 to 1. Then take the absolute value of each sample (with Math.Abs) and compare it to a threshold value. If any sample is above the threshold then that period is not silence.

Upvotes: 3

Related Questions