How can I determine the length (i.e. duration) of a .wav file in C#?

后端 未结 15 2286
逝去的感伤
逝去的感伤 2020-11-30 00:26

In the uncompressed situation I know I need to read the wav header, pull out the number of channels, bits, and sample rate and work it out from there: (channels) * (bits) *

15条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 01:14

    Download NAudio.dll from the link http://naudio.codeplex.com/

    and then use this function

    public static TimeSpan GetWavFileDuration(string fileName)       
    {     
        WaveFileReader wf = new WaveFileReader(fileName);
        return wf.TotalTime; 
    }
    

    you will get the Duration

提交回复
热议问题