From d3825debffe14656cacbb18e919fd412456ae91f Mon Sep 17 00:00:00 2001 From: Ephraim Kunz Date: Tue, 22 Nov 2022 10:10:03 -0700 Subject: [PATCH] Fix print_system_info return value --- src/standalone.rs | 10 ++++++---- src/utilities.rs | 1 + src/whisper_ctx.rs | 2 +- sys/build.rs | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/standalone.rs b/src/standalone.rs index 01262b0..3f36e71 100644 --- a/src/standalone.rs +++ b/src/standalone.rs @@ -1,7 +1,7 @@ //! Standalone functions that have no associated type. use crate::WhisperToken; -use std::ffi::{c_int, CString}; +use std::ffi::{c_int, CStr, CString}; /// Return the id of the specified language, returns -1 if not found /// @@ -47,6 +47,8 @@ pub fn token_transcribe() -> WhisperToken { /// /// # C++ equivalent /// `const char * whisper_print_system_info()` -pub fn print_system_info() { - unsafe { whisper_rs_sys::whisper_print_system_info() }; -} +pub fn print_system_info() -> &'static str { + let c_buf = unsafe { whisper_rs_sys::whisper_print_system_info() }; + let c_str = unsafe { CStr::from_ptr(c_buf) }; + c_str.to_str().unwrap() +} \ No newline at end of file diff --git a/src/utilities.rs b/src/utilities.rs index 47b3374..4d210b8 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -111,6 +111,7 @@ pub fn convert_stereo_to_mono_audio_simd(samples: &[f32]) -> Vec { mono } +#[cfg(feature = "simd")] #[cfg(test)] mod test { use super::*; diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index b479dcc..514f172 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -363,7 +363,7 @@ impl WhisperContext { unsafe { whisper_rs_sys::whisper_token_beg(self.ctx) } } - /// Print performance statistics to stdout. + /// Print performance statistics to stderr. /// /// # C++ equivalent /// `void whisper_print_timings(struct whisper_context * ctx)` diff --git a/sys/build.rs b/sys/build.rs index f009a98..e7a60aa 100644 --- a/sys/build.rs +++ b/sys/build.rs @@ -12,7 +12,8 @@ fn main() { let _: u64 = std::fs::copy( "src/bindings.rs", env::var("OUT_DIR").unwrap() + "/bindings.rs", - ).expect("Failed to copy bindings.rs"); + ) + .expect("Failed to copy bindings.rs"); } else { let bindings = bindgen::Builder::default() .header("wrapper.h") @@ -34,7 +35,7 @@ fn main() { "src/bindings.rs", env::var("OUT_DIR").unwrap() + "/bindings.rs", ) - .expect("Unable to copy bindings.rs"); + .expect("Unable to copy bindings.rs"); } } };