diff --git a/src/error.rs b/src/error.rs index 5807a90..51ab0bc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -39,6 +39,8 @@ pub enum WhisperError { InvalidText, /// Creating a state pointer failed. Check stderr for more information. FailedToCreateState, + /// No samples were provided. + NoSamples, } impl From for WhisperError { @@ -106,6 +108,7 @@ impl std::fmt::Display for WhisperError { "Generic whisper error. Varies depending on the function. Error code: {}", c_int ), + NoSamples => write!(f, "Input sample buffer was empty."), } } } diff --git a/src/whisper_state.rs b/src/whisper_state.rs index c49e2b6..f336638 100644 --- a/src/whisper_state.rs +++ b/src/whisper_state.rs @@ -327,6 +327,11 @@ impl<'a> WhisperState<'a> { /// # C++ equivalent /// `int whisper_full(struct whisper_context * ctx, struct whisper_full_params params, const float * samples, int n_samples)` 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); + } + let ret = unsafe { whisper_rs_sys::whisper_full_with_state( self.ctx,