Skip to content

Commit

Permalink
Merge pull request #79 from travolin/tweak/segment-vec-access
Browse files Browse the repository at this point in the history
Add access to segment text as bytes
  • Loading branch information
tazz4843 authored Aug 18, 2023
2 parents b7615db + bdfbeb6 commit 24e6a00
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/whisper_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,26 @@ impl<'a> WhisperState<'a> {
Ok(r_str.to_string())
}

/// Get the bytes of the specified segment.
///
/// # Arguments
/// * segment: Segment index.
///
/// # Returns
/// Ok(Vec<u8>) on success, Err(WhisperError) on failure.
///
/// # C++ equivalent
/// `const char * whisper_full_get_segment_text(struct whisper_context * ctx, int i_segment)`
pub fn full_get_segment_bytes(&self, segment: c_int) -> Result<Vec<u8>, WhisperError> {
let ret =
unsafe { whisper_rs_sys::whisper_full_get_segment_text_from_state(self.ptr, segment) };
if ret.is_null() {
return Err(WhisperError::NullPointer);
}
let c_str = unsafe { CStr::from_ptr(ret) };
Ok(c_str.to_bytes().to_vec())
}

/// Get number of tokens in the specified segment.
///
/// # Arguments
Expand Down

0 comments on commit 24e6a00

Please sign in to comment.