Skip to main content

whisper_rs/
lib.rs

1#![allow(clippy::uninlined_format_args)]
2#![cfg_attr(test, feature(test))]
3
4//! Most users will be looking for nothing more than [`WhisperState::full`] to run a full transcription pipeline.
5//!
6//! You can get a [`WhisperState`] by first creating a [`WhisperContext`] using [`WhisperContext::new_with_params`],
7//! and then calling [`WhisperContext::create_state`].
8
9#[cfg(feature = "vulkan")]
10pub mod vulkan;
11
12mod common_logging;
13mod error;
14mod ggml_logging_hook;
15mod standalone;
16mod utilities;
17mod whisper_ctx;
18mod whisper_ctx_wrapper;
19mod whisper_grammar;
20mod whisper_logging_hook;
21mod whisper_params;
22mod whisper_state;
23mod whisper_vad;
24
25pub use common_logging::GGMLLogLevel;
26pub use error::WhisperError;
27pub use standalone::*;
28pub use utilities::*;
29pub use whisper_ctx::DtwMode;
30pub use whisper_ctx::DtwModelPreset;
31pub use whisper_ctx::DtwParameters;
32pub use whisper_ctx::WhisperContextParameters;
33use whisper_ctx::WhisperInnerContext;
34pub use whisper_ctx_wrapper::WhisperContext;
35pub use whisper_grammar::{WhisperGrammarElement, WhisperGrammarElementType};
36pub use whisper_params::{FullParams, SamplingStrategy, SegmentCallbackData};
37#[cfg(feature = "raw-api")]
38pub use whisper_rs_sys;
39pub use whisper_state::{WhisperSegment, WhisperState, WhisperStateSegmentIterator, WhisperToken};
40pub use whisper_vad::*;
41
42pub type WhisperSysContext = whisper_rs_sys::whisper_context;
43pub type WhisperSysState = whisper_rs_sys::whisper_state;
44
45pub type WhisperTokenData = whisper_rs_sys::whisper_token_data;
46pub type WhisperTokenId = whisper_rs_sys::whisper_token;
47pub type WhisperNewSegmentCallback = whisper_rs_sys::whisper_new_segment_callback;
48pub type WhisperStartEncoderCallback = whisper_rs_sys::whisper_encoder_begin_callback;
49pub type WhisperProgressCallback = whisper_rs_sys::whisper_progress_callback;
50pub type WhisperLogitsFilterCallback = whisper_rs_sys::whisper_logits_filter_callback;
51pub type WhisperAbortCallback = whisper_rs_sys::ggml_abort_callback;
52pub type WhisperLogCallback = whisper_rs_sys::ggml_log_callback;
53pub type DtwAhead = whisper_rs_sys::whisper_ahead;
54
55/// The version of whisper.cpp that whisper-rs was linked with.
56pub static WHISPER_CPP_VERSION: &str = env!("WHISPER_CPP_VERSION");
57
58/// Redirect all whisper.cpp and GGML logs to logging hooks installed by whisper-rs.
59///
60/// This will stop most logs from being output to stdout/stderr and will bring them into
61/// `log` or `tracing`, if the `log_backend` or `tracing_backend` features, respectively,
62/// are enabled. If neither is enabled, this will essentially disable logging, as they won't
63/// be output anywhere.
64///
65/// Note whisper.cpp and GGML do not reliably follow Rust logging conventions.
66/// Use your logging crate's configuration to control how these logs will be output.
67/// whisper-rs does not currently output any logs, but this may change in the future.
68/// You should configure by module path and use `whisper_rs::ggml_logging_hook`,
69/// and/or `whisper_rs::whisper_logging_hook`, to avoid possibly ignoring useful
70/// `whisper-rs` logs in the future.
71///
72/// Safe to call multiple times. Only has an effect the first time.
73/// (note this means installing your own logging handlers with unsafe functions after this call
74/// is permanent and cannot be undone)
75pub fn install_logging_hooks() {
76    crate::whisper_logging_hook::install_whisper_logging_hook();
77    crate::ggml_logging_hook::install_ggml_logging_hook();
78}