Skip to content

Commit

Permalink
Merge pull request #137 from thewh1teagle/fix/transcription-example
Browse files Browse the repository at this point in the history
fix: transcription example compile errors
  • Loading branch information
tazz4843 authored Apr 14, 2024
2 parents 3c28886 + b94f234 commit e81f90f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions examples/audio_transcription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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::<i16>()
.map(|s| s.expect("invalid sample"))
.collect::<Vec<_>>(),
);
let samples: Vec<i16> = reader
.into_samples::<i16>()
.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");
}
Expand Down

0 comments on commit e81f90f

Please sign in to comment.