From d9e8713be795a0b0bcf33bf1fb9704c33ad460ce Mon Sep 17 00:00:00 2001 From: Niko Date: Sat, 6 Apr 2024 11:38:01 -0600 Subject: [PATCH] Fix examples --- examples/basic_use.rs | 8 +++++--- examples/full_usage/src/main.rs | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/basic_use.rs b/examples/basic_use.rs index 29cafe9..8627473 100644 --- a/examples/basic_use.rs +++ b/examples/basic_use.rs @@ -39,9 +39,11 @@ pub fn usage() -> Result<(), &'static str> { // note that you don't need to use these, you can do it yourself or any other way you want // these are just provided for convenience // SIMD variants of these functions are also available, but only on nightly Rust: see the docs - let audio_data = whisper_rs::convert_stereo_to_mono_audio( - &whisper_rs::convert_integer_to_float_audio(&audio_data), - )?; + let mut inter_audio_data = Vec::with_capacity(audio_data.len()); + whisper_rs::convert_integer_to_float_audio(&audio_data, &mut inter_audio_data) + .expect("failed to convert audio data"); + let audio_data = whisper_rs::convert_stereo_to_mono_audio(&inter_audio_data) + .expect("failed to convert audio data"); // now we can run the model // note the key we use here is the one we created above diff --git a/examples/full_usage/src/main.rs b/examples/full_usage/src/main.rs index eee6658..a6d0557 100644 --- a/examples/full_usage/src/main.rs +++ b/examples/full_usage/src/main.rs @@ -43,12 +43,15 @@ fn main() { } let original_samples = parse_wav_file(audio_path); - let samples = whisper_rs::convert_integer_to_float_audio(&original_samples); + let mut samples = Vec::with_capacity(original_samples.len()); + whisper_rs::convert_integer_to_float_audio(&original_samples, &mut samples) + .expect("failed to convert samples"); let ctx = WhisperContext::new_with_params( &whisper_path.to_string_lossy(), - WhisperContextParameters::default() - ).expect("failed to open model"); + WhisperContextParameters::default(), + ) + .expect("failed to open model"); let mut state = ctx.create_state().expect("failed to create key"); let mut params = FullParams::new(SamplingStrategy::default()); params.set_initial_prompt("experience");