From e00568e80190a7c7df3042790809d7a281bf772a Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 5 May 2023 22:47:46 -0600 Subject: [PATCH 1/3] reword error message in example and remove is_file check --- examples/full_usage/src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/full_usage/src/main.rs b/examples/full_usage/src/main.rs index 3c544e0..f0ab500 100644 --- a/examples/full_usage/src/main.rs +++ b/examples/full_usage/src/main.rs @@ -31,15 +31,15 @@ fn main() { .nth(1) .expect("first argument should be path to WAV file"); let audio_path = Path::new(&arg1); - if !audio_path.exists() && !audio_path.is_file() { - panic!("expected a file"); + if !audio_path.exists() { + panic!("audio file doesn't exist"); } let arg2 = std::env::args() .nth(2) .expect("second argument should be path to Whisper model"); let whisper_path = Path::new(&arg2); - if !whisper_path.exists() && !whisper_path.is_file() { - panic!("expected a whisper directory") + if !whisper_path.exists() { + panic!("whisper file doesn't exist") } let original_samples = parse_wav_file(audio_path); From 6e4c66db0a782322a4f66ab0fec00e8d64d3fe8e Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 5 May 2023 22:48:12 -0600 Subject: [PATCH 2/3] add timer for how long transcription takes --- examples/full_usage/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/full_usage/src/main.rs b/examples/full_usage/src/main.rs index f0ab500..bfabef0 100644 --- a/examples/full_usage/src/main.rs +++ b/examples/full_usage/src/main.rs @@ -50,8 +50,11 @@ fn main() { let mut state = ctx.create_state().expect("failed to create key"); let params = FullParams::new(SamplingStrategy::default()); - state.full(params, &samples) + let st = std::time::Instant::now(); + state + .full(params, &samples) .expect("failed to convert samples"); + let et = std::time::Instant::now(); let num_segments = state.full_n_segments().expect("failed to get number of segments"); for i in 0..num_segments { @@ -60,4 +63,5 @@ fn main() { let end_timestamp = state.full_get_segment_t1(i).expect("failed to get end timestamp"); println!("[{} - {}]: {}", start_timestamp, end_timestamp, segment); } + println!("took {}ms", (et - st).as_millis()); } From 0859b41191dcbf176f9924eb82854262c3417b42 Mon Sep 17 00:00:00 2001 From: Zero Date: Fri, 5 May 2023 22:48:20 -0600 Subject: [PATCH 3/3] `cargo fmt` --- examples/full_usage/src/main.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/full_usage/src/main.rs b/examples/full_usage/src/main.rs index bfabef0..42c0bff 100644 --- a/examples/full_usage/src/main.rs +++ b/examples/full_usage/src/main.rs @@ -45,8 +45,7 @@ fn main() { let original_samples = parse_wav_file(audio_path); let samples = whisper_rs::convert_integer_to_float_audio(&original_samples); - let ctx = - WhisperContext::new(&whisper_path.to_string_lossy()).expect("failed to open model"); + let ctx = WhisperContext::new(&whisper_path.to_string_lossy()).expect("failed to open model"); let mut state = ctx.create_state().expect("failed to create key"); let params = FullParams::new(SamplingStrategy::default()); @@ -56,11 +55,19 @@ fn main() { .expect("failed to convert samples"); let et = std::time::Instant::now(); - let num_segments = state.full_n_segments().expect("failed to get number of segments"); + let num_segments = state + .full_n_segments() + .expect("failed to get number of segments"); for i in 0..num_segments { - let segment = state.full_get_segment_text(i).expect("failed to get segment"); - let start_timestamp = state.full_get_segment_t0(i).expect("failed to get start timestamp"); - let end_timestamp = state.full_get_segment_t1(i).expect("failed to get end timestamp"); + let segment = state + .full_get_segment_text(i) + .expect("failed to get segment"); + let start_timestamp = state + .full_get_segment_t0(i) + .expect("failed to get start timestamp"); + let end_timestamp = state + .full_get_segment_t1(i) + .expect("failed to get end timestamp"); println!("[{} - {}]: {}", start_timestamp, end_timestamp, segment); } println!("took {}ms", (et - st).as_millis());