Skip to content

Commit

Permalink
Merge branch 'master' into cmake-change-build-type
Browse files Browse the repository at this point in the history
  • Loading branch information
tazz4843 authored Jan 4, 2024
2 parents 5061acf + 27042a4 commit 134067b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Utf8Error> for WhisperError {
Expand Down Expand Up @@ -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."),
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/whisper_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<c_int, WhisperError> {
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,
Expand Down

0 comments on commit 134067b

Please sign in to comment.