fix: transcription example compile errors

This commit is contained in:
thewh1teagle 2024-04-15 01:12:49 +03:00
parent a9e060571a
commit b94f2348dc
No known key found for this signature in database
GPG key ID: F7BFC3A4192804E4

View file

@ -35,7 +35,7 @@ fn main() -> Result<(), &'static str> {
params.set_print_timestamps(false); params.set_print_timestamps(false);
// Open the audio file. // 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)] #[allow(unused_variables)]
let hound::WavSpec { let hound::WavSpec {
channels, channels,
@ -45,18 +45,18 @@ fn main() -> Result<(), &'static str> {
} = reader.spec(); } = reader.spec();
// Convert the audio to floating point samples. // Convert the audio to floating point samples.
let mut audio = whisper_rs::convert_integer_to_float_audio( let samples: Vec<i16> = reader
&reader .into_samples::<i16>()
.samples::<i16>() .map(|x| x.expect("Invalid sample"))
.map(|s| s.expect("invalid sample")) .collect();
.collect::<Vec<_>>(), 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. // 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. // 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). // SIMD variants of these functions are also available on nightly Rust (see the docs).
if channels == 2 { 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 { } else if channels != 1 {
panic!(">2 channels unsupported"); panic!(">2 channels unsupported");
} }