use std::ffi::{c_int, CStr, CString};
pub fn get_lang_id(lang: &str) -> Option<c_int> {
let c_lang = CString::new(lang).expect("Language contains null byte");
let ret = unsafe { whisper_rs_sys::whisper_lang_id(c_lang.as_ptr()) };
if ret == -1 {
None
} else {
Some(ret)
}
}
pub fn get_lang_max_id() -> i32 {
unsafe { whisper_rs_sys::whisper_lang_max_id() }
}
pub fn get_lang_str(id: i32) -> Option<&'static str> {
let c_buf = unsafe { whisper_rs_sys::whisper_lang_str(id) };
if c_buf.is_null() {
None
} else {
let c_str = unsafe { CStr::from_ptr(c_buf) };
Some(c_str.to_str().unwrap())
}
}
pub fn get_lang_str_full(id: i32) -> Option<&'static str> {
let c_buf = unsafe { whisper_rs_sys::whisper_lang_str_full(id) };
if c_buf.is_null() {
None
} else {
let c_str = unsafe { CStr::from_ptr(c_buf) };
Some(c_str.to_str().unwrap())
}
}
pub unsafe fn set_log_callback(
log_callback: crate::WhisperLogCallback,
user_data: *mut std::ffi::c_void,
) {
unsafe {
whisper_rs_sys::whisper_log_set(log_callback, user_data);
}
}
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()
}
pub struct SystemInfo {
pub avx: bool,
pub avx2: bool,
pub fma: bool,
pub f16c: bool,
pub blas: bool,
pub cuda: bool,
}
impl Default for SystemInfo {
fn default() -> Self {
unsafe {
Self {
avx: whisper_rs_sys::ggml_cpu_has_avx() != 0,
avx2: whisper_rs_sys::ggml_cpu_has_avx2() != 0,
fma: whisper_rs_sys::ggml_cpu_has_fma() != 0,
f16c: whisper_rs_sys::ggml_cpu_has_f16c() != 0,
blas: whisper_rs_sys::ggml_cpu_has_blas() != 0,
cuda: whisper_rs_sys::ggml_cpu_has_cuda() != 0,
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_openblas() {
let info = SystemInfo::default();
assert_eq!(info.blas, cfg!(feature = "openblas"));
}
}