From e4f8910b1bfe528d5b64df71675137a157a22558 Mon Sep 17 00:00:00 2001 From: jiahua Date: Tue, 30 Apr 2024 09:09:52 +0800 Subject: [PATCH] fix: keep &mut self --- src/whisper_ctx.rs | 2 +- src/whisper_ctx_wrapper.rs | 2 +- src/whisper_state.rs | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index 2cc1df1..910a2c4 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -510,7 +510,7 @@ impl WhisperInnerContext { /// /// # C++ equivalent /// `bool whisper_full_get_segment_speaker_turn_next(struct whisper_context * ctx, int i_segment)` - pub fn full_get_segment_speaker_turn_next(&self, i_segment: c_int) -> bool { + pub fn full_get_segment_speaker_turn_next(&mut self, i_segment: c_int) -> bool { unsafe { whisper_rs_sys::whisper_full_get_segment_speaker_turn_next(self.ctx, i_segment) } } } diff --git a/src/whisper_ctx_wrapper.rs b/src/whisper_ctx_wrapper.rs index 3462126..4e5fa8c 100644 --- a/src/whisper_ctx_wrapper.rs +++ b/src/whisper_ctx_wrapper.rs @@ -448,7 +448,7 @@ impl WhisperContext { /// /// # C++ equivalent /// `bool whisper_full_get_segment_speaker_turn_next(struct whisper_context * ctx, int i_segment)` - pub fn full_get_segment_speaker_turn_next(&self, i_segment: c_int) -> bool { + pub fn full_get_segment_speaker_turn_next(&mut self, i_segment: c_int) -> bool { self.ctx.full_get_segment_speaker_turn_next(i_segment) } diff --git a/src/whisper_state.rs b/src/whisper_state.rs index 9fbd0bd..6805aa5 100644 --- a/src/whisper_state.rs +++ b/src/whisper_state.rs @@ -42,7 +42,7 @@ impl WhisperState { /// /// # C++ equivalent /// `int whisper_pcm_to_mel(struct whisper_context * ctx, const float * samples, int n_samples, int n_threads)` - pub fn pcm_to_mel(&self, pcm: &[f32], threads: usize) -> Result<(), WhisperError> { + pub fn pcm_to_mel(&mut self, pcm: &[f32], threads: usize) -> Result<(), WhisperError> { if threads < 1 { return Err(WhisperError::InvalidThreadCount); } @@ -78,7 +78,7 @@ impl WhisperState { /// # C++ equivalent /// `int whisper_pcm_to_mel(struct whisper_context * ctx, const float * samples, int n_samples, int n_threads)` pub fn pcm_to_mel_phase_vocoder( - &self, + &mut self, pcm: &[f32], threads: usize, ) -> Result<(), WhisperError> { @@ -119,7 +119,7 @@ impl WhisperState { /// /// # C++ equivalent /// `int whisper_set_mel(struct whisper_context * ctx, const float * data, int n_len, int n_mel)` - pub fn set_mel(&self, data: &[f32]) -> Result<(), WhisperError> { + pub fn set_mel(&mut self, data: &[f32]) -> Result<(), WhisperError> { let hop_size = 160; let n_len = (data.len() / hop_size) * 2; let ret = unsafe { @@ -152,7 +152,7 @@ impl WhisperState { /// /// # C++ equivalent /// `int whisper_encode(struct whisper_context * ctx, int offset, int n_threads)` - pub fn encode(&self, offset: usize, threads: usize) -> Result<(), WhisperError> { + pub fn encode(&mut self, offset: usize, threads: usize) -> Result<(), WhisperError> { if threads < 1 { return Err(WhisperError::InvalidThreadCount); } @@ -189,7 +189,7 @@ impl WhisperState { /// # C++ equivalent /// `int whisper_decode(struct whisper_context * ctx, const whisper_token * tokens, int n_tokens, int n_past, int n_threads)` pub fn decode( - &self, + &mut self, tokens: &[WhisperToken], n_past: usize, threads: usize, @@ -324,7 +324,7 @@ impl WhisperState { /// /// # C++ equivalent /// `int whisper_full(struct whisper_context * ctx, struct whisper_full_params params, const float * samples, int n_samples)` - pub fn full(&self, params: FullParams, data: &[f32]) -> Result { + pub fn full(&mut self, params: FullParams, data: &[f32]) -> Result { if data.is_empty() { // can randomly trigger segmentation faults if we don't check this return Err(WhisperError::NoSamples); @@ -613,7 +613,7 @@ impl WhisperState { /// /// # C++ equivalent /// `bool whisper_full_get_segment_speaker_turn_next_from_state(struct whisper_state * state, int i_segment)` - pub fn full_get_segment_speaker_turn_next(&self, i_segment: c_int) -> bool { + pub fn full_get_segment_speaker_turn_next(&mut self, i_segment: c_int) -> bool { unsafe { whisper_rs_sys::whisper_full_get_segment_speaker_turn_next_from_state( self.ptr, i_segment,