From f30d0ea0a1ae0f12d8e14edfd6a06d42003ec38f Mon Sep 17 00:00:00 2001 From: jiahua Date: Fri, 26 Apr 2024 16:23:21 +0800 Subject: [PATCH] fix: rustfmt --- examples/full_usage/src/main.rs | 2 +- src/lib.rs | 4 ++-- src/whisper_ctx.rs | 1 - src/whisper_ctx_wrapper.rs | 12 +++++------- src/whisper_state.rs | 17 ++++++++++------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/full_usage/src/main.rs b/examples/full_usage/src/main.rs index 03b5daf..c3352fd 100644 --- a/examples/full_usage/src/main.rs +++ b/examples/full_usage/src/main.rs @@ -43,7 +43,7 @@ fn main() { } let original_samples = parse_wav_file(audio_path); - let mut samples = vec![0.0f32; original_samples.len()]; + let mut samples = vec![0.0f32; original_samples.len()]; whisper_rs::convert_integer_to_float_audio(&original_samples, &mut samples) .expect("failed to convert samples"); diff --git a/src/lib.rs b/src/lib.rs index 88926ab..f5dc43f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ mod error; mod standalone; mod utilities; mod whisper_ctx; +mod whisper_ctx_wrapper; mod whisper_grammar; mod whisper_params; mod whisper_state; @@ -12,7 +13,6 @@ mod whisper_state; mod whisper_sys_log; #[cfg(feature = "whisper-cpp-tracing")] mod whisper_sys_tracing; -mod whisper_ctx_wrapper; #[cfg(any(feature = "whisper-cpp-log", feature = "whisper-cpp-tracing"))] static LOG_TRAMPOLINE_INSTALL: Once = Once::new(); @@ -22,9 +22,9 @@ pub use standalone::*; #[cfg(any(feature = "whisper-cpp-log", feature = "whisper-cpp-tracing"))] use std::sync::Once; pub use utilities::*; +pub use whisper_ctx::WhisperContextParameters; use whisper_ctx::WhisperInnerContext; pub use whisper_ctx_wrapper::WhisperContext; -pub use whisper_ctx::WhisperContextParameters; pub use whisper_grammar::{WhisperGrammarElement, WhisperGrammarElementType}; pub use whisper_params::{FullParams, SamplingStrategy}; #[cfg(feature = "raw-api")] diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index d7415ab..2cc1df1 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -114,7 +114,6 @@ impl WhisperInnerContext { } } - /// Convert the provided text into tokens. /// /// # Arguments diff --git a/src/whisper_ctx_wrapper.rs b/src/whisper_ctx_wrapper.rs index b20379f..3462126 100644 --- a/src/whisper_ctx_wrapper.rs +++ b/src/whisper_ctx_wrapper.rs @@ -1,7 +1,9 @@ use std::ffi::{c_int, CStr}; use std::sync::Arc; -use crate::{WhisperInnerContext, WhisperContextParameters, WhisperError, WhisperState, WhisperToken}; +use crate::{ + WhisperContextParameters, WhisperError, WhisperInnerContext, WhisperState, WhisperToken, +}; pub struct WhisperContext { ctx: Arc, @@ -9,9 +11,7 @@ pub struct WhisperContext { impl WhisperContext { fn wrap(ctx: WhisperInnerContext) -> Self { - Self { - ctx: Arc::new(ctx), - } + Self { ctx: Arc::new(ctx) } } /// Create a new WhisperContext from a file, with parameters. @@ -83,7 +83,6 @@ impl WhisperContext { Ok(Self::wrap(ctx)) } - /// Convert the provided text into tokens. /// /// # Arguments @@ -453,7 +452,6 @@ impl WhisperContext { self.ctx.full_get_segment_speaker_turn_next(i_segment) } - // we don't implement `whisper_init()` here since i have zero clue what `whisper_model_loader` does /// Create a new state object, ready for use. @@ -472,4 +470,4 @@ impl WhisperContext { Ok(WhisperState::new(self.ctx.clone(), state)) } } -} \ No newline at end of file +} diff --git a/src/whisper_state.rs b/src/whisper_state.rs index 025c109..9fbd0bd 100644 --- a/src/whisper_state.rs +++ b/src/whisper_state.rs @@ -1,7 +1,7 @@ use std::ffi::{c_int, CStr}; use std::sync::Arc; -use crate::{FullParams, WhisperInnerContext, WhisperError, WhisperToken, WhisperTokenData}; +use crate::{FullParams, WhisperError, WhisperInnerContext, WhisperToken, WhisperTokenData}; /// Rustified pointer to a Whisper state. #[derive(Debug)] @@ -27,10 +27,7 @@ impl WhisperState { ctx: Arc, ptr: *mut whisper_rs_sys::whisper_state, ) -> Self { - Self { - ctx, - ptr, - } + Self { ctx, ptr } } /// Convert raw PCM audio (floating point 32 bit) to log mel spectrogram. @@ -495,7 +492,10 @@ impl WhisperState { ) -> Result { let ret = unsafe { whisper_rs_sys::whisper_full_get_token_text_from_state( - self.ctx.ctx, self.ptr, segment, token, + self.ctx.ctx, + self.ptr, + segment, + token, ) }; if ret.is_null() { @@ -527,7 +527,10 @@ impl WhisperState { ) -> Result { let ret = unsafe { whisper_rs_sys::whisper_full_get_token_text_from_state( - self.ctx.ctx, self.ptr, segment, token, + self.ctx.ctx, + self.ptr, + segment, + token, ) }; if ret.is_null() {