remove useless error handling

This commit is contained in:
0/0 2022-12-14 17:08:37 -07:00
parent 462f6c7b13
commit b4459e5e53
No known key found for this signature in database
GPG key ID: 3861E636EA1E0E2B

View file

@ -222,49 +222,37 @@ impl WhisperContext {
/// Get the mel spectrogram length. /// Get the mel spectrogram length.
/// ///
/// # Returns /// # Returns
/// Ok(c_int) on success, Err(WhisperError) on failure. /// c_int
/// ///
/// # C++ equivalent /// # C++ equivalent
/// `int whisper_n_len (struct whisper_context * ctx)` /// `int whisper_n_len (struct whisper_context * ctx)`
pub fn n_len(&self) -> Result<c_int, WhisperError> { #[inline]
let ret = unsafe { whisper_rs_sys::whisper_n_len(self.ctx) }; pub fn n_len(&self) -> c_int {
if ret < 0 { unsafe { whisper_rs_sys::whisper_n_len(self.ctx) }
Err(WhisperError::GenericError(ret))
} else {
Ok(ret as c_int)
}
} }
/// Get n_vocab. /// Get n_vocab.
/// ///
/// # Returns /// # Returns
/// Ok(c_int) on success, Err(WhisperError) on failure. /// c_int
/// ///
/// # C++ equivalent /// # C++ equivalent
/// `int whisper_n_vocab (struct whisper_context * ctx)` /// `int whisper_n_vocab (struct whisper_context * ctx)`
pub fn n_vocab(&self) -> Result<c_int, WhisperError> { #[inline]
let ret = unsafe { whisper_rs_sys::whisper_n_vocab(self.ctx) }; pub fn n_vocab(&self) -> c_int {
if ret < 0 { unsafe { whisper_rs_sys::whisper_n_vocab(self.ctx) }
Err(WhisperError::GenericError(ret))
} else {
Ok(ret as c_int)
}
} }
/// Get n_text_ctx. /// Get n_text_ctx.
/// ///
/// # Returns /// # Returns
/// Ok(c_int) on success, Err(WhisperError) on failure. /// c_int
/// ///
/// # C++ equivalent /// # C++ equivalent
/// `int whisper_n_text_ctx (struct whisper_context * ctx)` /// `int whisper_n_text_ctx (struct whisper_context * ctx)`
pub fn n_text_ctx(&self) -> Result<c_int, WhisperError> { #[inline]
let ret = unsafe { whisper_rs_sys::whisper_n_text_ctx(self.ctx) }; pub fn n_text_ctx(&self) -> c_int {
if ret < 0 { unsafe { whisper_rs_sys::whisper_n_text_ctx(self.ctx) }
Err(WhisperError::GenericError(ret))
} else {
Ok(ret as c_int)
}
} }
/// Does this model support multiple languages? /// Does this model support multiple languages?
@ -453,17 +441,13 @@ impl WhisperContext {
/// * segment: Segment index. /// * segment: Segment index.
/// ///
/// # Returns /// # Returns
/// Ok(c_int) on success, Err(WhisperError) on failure. /// c_int
/// ///
/// # C++ equivalent /// # C++ equivalent
/// `int whisper_full_n_tokens(struct whisper_context * ctx, int i_segment)` /// `int whisper_full_n_tokens(struct whisper_context * ctx, int i_segment)`
pub fn full_n_tokens(&self, segment: c_int) -> Result<c_int, WhisperError> { #[inline]
let ret = unsafe { whisper_rs_sys::whisper_full_n_tokens(self.ctx, segment) }; pub fn full_n_tokens(&self, segment: c_int) -> c_int {
if ret < 0 { unsafe { whisper_rs_sys::whisper_full_n_tokens(self.ctx, segment) }
Err(WhisperError::GenericError(ret))
} else {
Ok(ret as c_int)
}
} }
/// Get the token text of the specified token in the specified segment. /// Get the token text of the specified token in the specified segment.