Skip to content

Commit

Permalink
Merge pull request ggerganov#4 from ephraimkunz/print-system-info
Browse files Browse the repository at this point in the history
Fix print_system_info to correctly return a static &str
  • Loading branch information
tazz4843 committed Dec 4, 2022
2 parents 520ea9d + d3825de commit 5fb138f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/standalone.rs
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down Expand Up @@ -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()
}
1 change: 1 addition & 0 deletions src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub fn convert_stereo_to_mono_audio_simd(samples: &[f32]) -> Vec<f32> {
mono
}

#[cfg(feature = "simd")]
#[cfg(test)]
mod test {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/whisper_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
5 changes: 3 additions & 2 deletions sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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");
}
}
};
Expand Down

0 comments on commit 5fb138f

Please sign in to comment.