From 908e96f9da7300c7cafc90b86f984a5451afd96f Mon Sep 17 00:00:00 2001 From: Jonathan Soo Date: Thu, 4 May 2023 19:17:29 -0400 Subject: [PATCH] Convert text to CString --- src/whisper_ctx.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index 98afa99..10ce2dd 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -88,12 +88,15 @@ impl WhisperContext { text: &str, max_tokens: usize, ) -> Result, 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 let mut tokens: Vec = Vec::with_capacity(max_tokens); let ret = unsafe { whisper_rs_sys::whisper_tokenize( self.ctx, - text.as_ptr() as *const _, + text.as_ptr(), tokens.as_mut_ptr(), max_tokens as c_int, )