Convert text to CString
This commit is contained in:
parent
b5072d486d
commit
908e96f9da
1 changed files with 4 additions and 1 deletions
|
|
@ -88,12 +88,15 @@ impl WhisperContext {
|
||||||
text: &str,
|
text: &str,
|
||||||
max_tokens: usize,
|
max_tokens: usize,
|
||||||
) -> Result<Vec<WhisperToken>, WhisperError> {
|
) -> Result<Vec<WhisperToken>, WhisperError> {
|
||||||
|
// convert the text to a nul-terminated C string. Will raise an error if the text contains
|
||||||
|
// any nul bytes.
|
||||||
|
let text = CString::new(text)?;
|
||||||
// allocate at least max_tokens to ensure the memory is valid
|
// allocate at least max_tokens to ensure the memory is valid
|
||||||
let mut tokens: Vec<WhisperToken> = Vec::with_capacity(max_tokens);
|
let mut tokens: Vec<WhisperToken> = Vec::with_capacity(max_tokens);
|
||||||
let ret = unsafe {
|
let ret = unsafe {
|
||||||
whisper_rs_sys::whisper_tokenize(
|
whisper_rs_sys::whisper_tokenize(
|
||||||
self.ctx,
|
self.ctx,
|
||||||
text.as_ptr() as *const _,
|
text.as_ptr(),
|
||||||
tokens.as_mut_ptr(),
|
tokens.as_mut_ptr(),
|
||||||
max_tokens as c_int,
|
max_tokens as c_int,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue