commit
a7caf1b96a
2 changed files with 18 additions and 4 deletions
|
|
@ -311,13 +311,27 @@ impl WhisperContext {
|
||||||
/// # C++ equivalent
|
/// # C++ equivalent
|
||||||
/// `const char * whisper_token_to_str(struct whisper_context * ctx, whisper_token token)`
|
/// `const char * whisper_token_to_str(struct whisper_context * ctx, whisper_token token)`
|
||||||
pub fn token_to_str(&self, token_id: WhisperToken) -> Result<String, WhisperError> {
|
pub fn token_to_str(&self, token_id: WhisperToken) -> Result<String, WhisperError> {
|
||||||
|
let c_str = self.token_to_cstr(token_id)?;
|
||||||
|
let r_str = c_str.to_str()?;
|
||||||
|
Ok(r_str.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a token ID to a &CStr.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * token_id: ID of the token.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// Ok(String) on success, Err(WhisperError) on failure.
|
||||||
|
///
|
||||||
|
/// # C++ equivalent
|
||||||
|
/// `const char * whisper_token_to_str(struct whisper_context * ctx, whisper_token token)`
|
||||||
|
pub fn token_to_cstr(&self, token_id: WhisperToken) -> Result<&CStr, WhisperError> {
|
||||||
let ret = unsafe { whisper_rs_sys::whisper_token_to_str(self.ctx, token_id) };
|
let ret = unsafe { whisper_rs_sys::whisper_token_to_str(self.ctx, token_id) };
|
||||||
if ret.is_null() {
|
if ret.is_null() {
|
||||||
return Err(WhisperError::NullPointer);
|
return Err(WhisperError::NullPointer);
|
||||||
}
|
}
|
||||||
let c_str = unsafe { CStr::from_ptr(ret) };
|
Ok(unsafe { CStr::from_ptr(ret) })
|
||||||
let r_str = c_str.to_str()?;
|
|
||||||
Ok(r_str.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Undocumented but exposed function in the C++ API.
|
/// Undocumented but exposed function in the C++ API.
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit c23588cc4b2c4be4ba3634a21c7f2b302c5f370e
|
Subproject commit 5108b30e6daf361c856abb6b86e5038500bdbeb1
|
||||||
Loading…
Add table
Add a link
Reference in a new issue