How to read Bit rate of .wav file in C#

后端 未结 2 1058
青春惊慌失措
青春惊慌失措 2021-01-13 09:46

given that I have a .wav file, what would be best way to read its Bit rate property in C#. I have tried Shell, and asked a question Is "Bit rate" property fixed i

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 10:41

    With NAudio, the bitrate is calculated via the AverageBytesPerSecond member of the WaveFormat structure:

    using (var reader = new WaveFileReader(filename))
    {
        bitrate = reader.WaveFormat.AverageBytesPerSecond * 8;
    }
    

    This will work for all uncompressed audio formats and most compressed. The WAV file format is a container format and can actually contain audio in any codec, even though it's most common use is PCM. But not all codecs are CBR (constant bit rate). Some have a variable bit rate, so the AverageBytesPerSecond property may be an estimate.

提交回复
热议问题