Skip to main content

transcribe_cpp_types/
family.rs

1//! Typed family-extension options.
2//!
3//! Each family exposes model-specific knobs via a kind-tagged extension struct
4//! (`include/transcribe/<family>.h`). These typed options mirror those structs:
5//! every field is an `Option`, and only the fields you set override the
6//! defaults the C `*_init()` stamps. A [`RunExtension`] attaches to
7//! [`RunOptions`](crate::RunOptions); a [`StreamExtension`] attaches to
8//! [`StreamOptions`](crate::StreamOptions); a [`DiarizeExtension`] attaches to
9//! [`DiarizeOptions`](crate::DiarizeOptions).
10//!
11//! Probe `transcribe_cpp::Model::accepts_ext` to learn whether a loaded model
12//! accepts a given kind on a slot; an unaccepted extension is rejected by
13//! `run`/`stream` with `transcribe_cpp::Error::InvalidArgument`.
14
15/// Whisper run-extension knobs (run slot): initial prompt, temperature
16/// fallback, and decode thresholds. `None` keeps the family default.
17/// `initial_prompt` cannot be combined with `RunOptions::vocabulary` / `prompt`.
18#[derive(Debug, Clone, Default, PartialEq)]
19#[cfg_attr(
20    feature = "serde",
21    derive(serde::Serialize, serde::Deserialize),
22    serde(default)
23)]
24pub struct WhisperRunOptions {
25    pub initial_prompt: Option<String>,
26    pub condition_on_prev_tokens: Option<bool>,
27    pub temperature: Option<f32>,
28    pub temperature_inc: Option<f32>,
29    pub compression_ratio_thold: Option<f32>,
30    pub logprob_thold: Option<f32>,
31    pub no_speech_thold: Option<f32>,
32    pub max_prev_context_tokens: Option<i32>,
33    pub seed: Option<u32>,
34    pub max_initial_timestamp: Option<f32>,
35}
36
37/// Moonshine-streaming stream-extension knobs (stream slot).
38#[derive(Debug, Clone, Default, PartialEq, Eq)]
39#[cfg_attr(
40    feature = "serde",
41    derive(serde::Serialize, serde::Deserialize),
42    serde(default)
43)]
44pub struct MoonshineStreamingOptions {
45    pub min_decode_interval_ms: Option<i32>,
46}
47
48/// Parakeet cache-aware streaming knobs (stream slot).
49#[derive(Debug, Clone, Default, PartialEq, Eq)]
50#[cfg_attr(
51    feature = "serde",
52    derive(serde::Serialize, serde::Deserialize),
53    serde(default)
54)]
55pub struct ParakeetStreamOptions {
56    pub att_context_right: Option<i32>,
57}
58
59/// Parakeet chunked-attention buffered streaming knobs (stream slot).
60#[derive(Debug, Clone, Default, PartialEq, Eq)]
61#[cfg_attr(
62    feature = "serde",
63    derive(serde::Serialize, serde::Deserialize),
64    serde(default)
65)]
66pub struct ParakeetBufferedStreamOptions {
67    pub left_ms: Option<i32>,
68    pub chunk_ms: Option<i32>,
69    pub right_ms: Option<i32>,
70}
71
72/// Voxtral-realtime streaming knobs (stream slot).
73#[derive(Debug, Clone, Default, PartialEq, Eq)]
74#[cfg_attr(
75    feature = "serde",
76    derive(serde::Serialize, serde::Deserialize),
77    serde(default)
78)]
79pub struct VoxtralRealtimeStreamOptions {
80    pub num_delay_tokens: Option<i32>,
81    pub min_decode_interval_ms: Option<i32>,
82}
83
84/// Sortformer streaming operating point (latency / accuracy trade-off).
85/// The menu is discrete (jointly-tuned bundles), not a latency dial;
86/// `Default` keeps the GGUF-shipped checkpoint configuration.
87#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
88#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89pub enum SortformerPreset {
90    #[default]
91    Default,
92    /// ~30.4 s algorithmic lookahead; the offline-file operating point.
93    VeryHighLatency,
94    /// ~10.0 s lookahead.
95    HighLatency,
96    /// ~1.04 s lookahead; the real-time point (compute-heavy per audio
97    /// second — many small windows).
98    LowLatency,
99}
100
101/// Sortformer diarize-extension knobs (diarize-run slot). `None` keeps the
102/// family default (the GGUF-shipped cfg).
103#[derive(Debug, Clone, Default, PartialEq, Eq)]
104#[cfg_attr(
105    feature = "serde",
106    derive(serde::Serialize, serde::Deserialize),
107    serde(default)
108)]
109pub struct SortformerDiarizeOptions {
110    pub preset: Option<SortformerPreset>,
111}
112
113/// A family extension for the diarize-run slot
114/// (`transcribe_cpp::DiarizeSession::run`).
115#[derive(Debug, Clone, PartialEq, Eq)]
116#[non_exhaustive]
117#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
118pub enum DiarizeExtension {
119    Sortformer(SortformerDiarizeOptions),
120}
121
122/// A family extension for the run slot (offline `run`/`run_batch`).
123#[derive(Debug, Clone, PartialEq)]
124#[non_exhaustive]
125#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
126pub enum RunExtension {
127    Whisper(WhisperRunOptions),
128}
129
130/// A family extension for the stream slot.
131#[derive(Debug, Clone, PartialEq, Eq)]
132#[non_exhaustive]
133#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
134pub enum StreamExtension {
135    ParakeetStream(ParakeetStreamOptions),
136    ParakeetBuffered(ParakeetBufferedStreamOptions),
137    MoonshineStreaming(MoonshineStreamingOptions),
138    VoxtralRealtime(VoxtralRealtimeStreamOptions),
139}