diff --git a/examples/audio_transcription.rs b/examples/audio_transcription.rs index 098502e..7661e04 100644 --- a/examples/audio_transcription.rs +++ b/examples/audio_transcription.rs @@ -35,7 +35,7 @@ fn main() -> Result<(), &'static str> { params.set_print_timestamps(false); // Open the audio file. - let mut reader = hound::WavReader::open("audio.wav").expect("failed to open file"); + let reader = hound::WavReader::open("audio.wav").expect("failed to open file"); #[allow(unused_variables)] let hound::WavSpec { channels, @@ -45,18 +45,18 @@ fn main() -> Result<(), &'static str> { } = reader.spec(); // Convert the audio to floating point samples. - let mut audio = whisper_rs::convert_integer_to_float_audio( - &reader - .samples::() - .map(|s| s.expect("invalid sample")) - .collect::>(), - ); + let samples: Vec = reader + .into_samples::() + .map(|x| x.expect("Invalid sample")) + .collect(); + let mut audio = vec![0.0f32; samples.len().try_into().unwrap()]; + whisper_rs::convert_integer_to_float_audio(&samples, &mut audio).expect("Conversion error"); // Convert audio to 16KHz mono f32 samples, as required by the model. // These utilities are provided for convenience, but can be replaced with custom conversion logic. // SIMD variants of these functions are also available on nightly Rust (see the docs). if channels == 2 { - audio = whisper_rs::convert_stereo_to_mono_audio(&audio)?; + audio = whisper_rs::convert_stereo_to_mono_audio(&audio).expect("Conversion error"); } else if channels != 1 { panic!(">2 channels unsupported"); }