Read a WAV file with WavReader
releaseTo decode audio data from a WAV file, use hound::WavReader. You can iterate over samples using the .samples::<T>() method, where T is a type implementing the Sample trait (e.g., i16, i32, f32).
Note that the type T must be compatible with the file's bit depth and SampleFormat to avoid InvalidSampleFormat or TooWide errors.
use hound;
let mut reader = hound::WavReader::open("testsamples/pop.wav").unwrap();
let sqr_sum = reader.samples::<i16>()
.fold(0.0, |sqr_sum, s| {
let sample = s.unwrap() as f64;
sqr_sum + sample * sample
});
println!("RMS is {}", (sqr_sum / reader.len() as f64).sqrt());