Fix compile errors
This commit is contained in:
parent
31b5976b17
commit
ffd6196caa
3 changed files with 21 additions and 22 deletions
|
|
@ -23,6 +23,10 @@ pub use whisper_ctx::WhisperContextParameters;
|
|||
pub use whisper_grammar::{WhisperGrammarElement, WhisperGrammarElementType};
|
||||
pub use whisper_params::{FullParams, SamplingStrategy};
|
||||
pub use whisper_state::WhisperState;
|
||||
#[cfg(feature = "whisper-cpp-log")]
|
||||
pub use whisper_sys_log::install_whisper_log_trampoline;
|
||||
#[cfg(feature = "whisper-cpp-tracing")]
|
||||
pub use whisper_sys_tracing::install_whisper_tracing_trampoline;
|
||||
|
||||
pub type WhisperSysContext = whisper_rs_sys::whisper_context;
|
||||
pub type WhisperSysState = whisper_rs_sys::whisper_state;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use log::{debug, error, info, warn};
|
||||
use std::sync::Once;
|
||||
use whisper_rs_sys::ggml_log_level;
|
||||
|
||||
unsafe extern "C" fn whisper_cpp_log_trampoline(
|
||||
|
|
@ -13,34 +12,31 @@ unsafe extern "C" fn whisper_cpp_log_trampoline(
|
|||
|
||||
// SAFETY: we must trust whisper.cpp that it will not pass us a string that does not satisfy
|
||||
// from_ptr's requirements.
|
||||
let log_str = unsafe { std::ffi::CStr::from_ptr(text) }
|
||||
.to_string_lossy()
|
||||
// whisper.cpp gives newlines at the end of its log messages, so we trim them
|
||||
.trim();
|
||||
let log_str = unsafe { std::ffi::CStr::from_ptr(text) }.to_string_lossy();
|
||||
// whisper.cpp gives newlines at the end of its log messages, so we trim them
|
||||
let trimmed = log_str.trim();
|
||||
|
||||
match level {
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_DEBUG => debug!("{}", log_str),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_INFO => info!("{}", log_str),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_WARN => warn!("{}", log_str),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_ERROR => error!("{}", log_str),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_DEBUG => debug!("{}", trimmed),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_INFO => info!("{}", trimmed),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_WARN => warn!("{}", trimmed),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_ERROR => error!("{}", trimmed),
|
||||
_ => {
|
||||
warn!(
|
||||
"whisper_cpp_log_trampoline: unknown log level {}: message: {}",
|
||||
level, log_str
|
||||
level, trimmed
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static LOG_TRAMPOLINE_INSTALL: Once = Once::new();
|
||||
|
||||
/// Shortcut utility to redirect all whisper.cpp logging to the `log` crate.
|
||||
///
|
||||
/// Filter for logs from the `whisper-rs` crate to see all log output from whisper.cpp.
|
||||
///
|
||||
/// You should only call this once (subsequent calls have no ill effect).
|
||||
pub fn install_whisper_log_trampoline() {
|
||||
LOG_TRAMPOLINE_INSTALL.call_once(|| unsafe {
|
||||
crate::LOG_TRAMPOLINE_INSTALL.call_once(|| unsafe {
|
||||
whisper_rs_sys::whisper_log_set(Some(whisper_cpp_log_trampoline), std::ptr::null_mut())
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::sync::Once;
|
||||
use tracing::{debug, error, info, warn};
|
||||
use whisper_rs_sys::ggml_log_level;
|
||||
|
||||
|
|
@ -13,19 +12,19 @@ unsafe extern "C" fn whisper_cpp_tracing_trampoline(
|
|||
|
||||
// SAFETY: we must trust whisper.cpp that it will not pass us a string that does not satisfy
|
||||
// from_ptr's requirements.
|
||||
let log_str = unsafe { std::ffi::CStr::from_ptr(text) }
|
||||
.to_string_lossy()
|
||||
.trim();
|
||||
let log_str = unsafe { std::ffi::CStr::from_ptr(text) }.to_string_lossy();
|
||||
// whisper.cpp gives newlines at the end of its log messages, so we trim them
|
||||
let trimmed = log_str.trim();
|
||||
|
||||
match level {
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_DEBUG => debug!("{}", log_str),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_INFO => info!("{}", log_str),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_WARN => warn!("{}", log_str),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_ERROR => error!("{}", log_str),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_DEBUG => debug!("{}", trimmed),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_INFO => info!("{}", trimmed),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_WARN => warn!("{}", trimmed),
|
||||
whisper_rs_sys::ggml_log_level_GGML_LOG_LEVEL_ERROR => error!("{}", trimmed),
|
||||
_ => {
|
||||
warn!(
|
||||
"whisper_cpp_tracing_trampoline: unknown log level {}: message: {}",
|
||||
level, log_str
|
||||
level, trimmed
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue