Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions bindings/python/src/transcribe_cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
Itn = Literal["default", "off", "on"]
Diarize = Literal["default", "off", "on"]
SortformerPreset = Literal["default", "very_high_latency", "high_latency", "low_latency"]
Nemotron3DiarPreset = Literal["default", "very_high_latency", "low_latency",
"very_low_latency", "ultra_low_latency"]
CommitPolicy = Literal["auto", "on_finalize", "stable_prefix"]
Feature = Literal[
"initial_prompt", "temperature_fallback", "long_form",
Expand Down Expand Up @@ -109,9 +111,11 @@
"ParakeetStreamOptions",
"ParakeetBufferedStreamOptions",
"SortformerDiarizeOptions",
"Nemotron3DiarDiarizeOptions",
"VoxtralRealtimeStreamOptions",
"Backend",
"SortformerPreset",
"Nemotron3DiarPreset",
"KVType",
"Task",
"Timestamps",
Expand Down Expand Up @@ -1056,6 +1060,40 @@ def _apply(self, ext) -> None:
ext.preset = self._presets[self.preset]


class Nemotron3DiarDiarizeOptions(FamilyExtension):
"""Nemotron-3-Diarization operating-point options for
``DiarizeSession.run()`` (diarize-run slot).

``preset`` picks the model card's latency / accuracy bundle:
``"very_high_latency"`` (30.4 s, the offline point; also ``"default"``),
``"low_latency"`` (1.04 s), ``"very_low_latency"`` (0.64 s),
``"ultra_low_latency"`` (0.32 s). Smaller chunks cost more compute per
audio second."""

_slot = "diarize_run"
_kind = _generated.TRANSCRIBE_EXT_KIND_NEMOTRON3_DIAR_DIARIZE
_struct = _generated.transcribe_nemotron3_diar_diarize_ext
_init = "transcribe_nemotron3_diar_diarize_ext_init"

_presets = {
"default": _generated.TRANSCRIBE_NEMOTRON3_DIAR_PRESET_DEFAULT,
"very_high_latency": _generated.TRANSCRIBE_NEMOTRON3_DIAR_PRESET_VERY_HIGH_LATENCY,
"low_latency": _generated.TRANSCRIBE_NEMOTRON3_DIAR_PRESET_LOW_LATENCY,
"very_low_latency": _generated.TRANSCRIBE_NEMOTRON3_DIAR_PRESET_VERY_LOW_LATENCY,
"ultra_low_latency": _generated.TRANSCRIBE_NEMOTRON3_DIAR_PRESET_ULTRA_LOW_LATENCY,
}

def __init__(self, *, preset: Nemotron3DiarPreset | None = None):
if preset is not None and preset not in self._presets:
raise ValueError(f"unknown nemotron3_diar preset {preset!r}; "
f"expected one of {sorted(self._presets)}")
self.preset = preset

def _apply(self, ext) -> None:
if self.preset is not None:
ext.preset = self._presets[self.preset]


# --- high-level handles ---------------------------------------------------


Expand Down
14 changes: 13 additions & 1 deletion bindings/python/src/transcribe_cpp/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Stable digest of the ABI surface below (structs, enums, macros, layout,
# prototypes). A native provider package echoes this back so the API
# package can reject an ABI-mismatched provider before dlopen.
PUBLIC_HEADER_HASH = "d550d6960224e260"
PUBLIC_HEADER_HASH = "fa695c0a3ae06edd"

# === enum constants ===
TRANSCRIBE_OK = 0
Expand Down Expand Up @@ -134,6 +134,11 @@
TRANSCRIBE_STREAM_COMMIT_AUTO = 0
TRANSCRIBE_STREAM_COMMIT_ON_FINALIZE = 1
TRANSCRIBE_STREAM_COMMIT_STABLE_PREFIX = 2
TRANSCRIBE_NEMOTRON3_DIAR_PRESET_DEFAULT = 0
TRANSCRIBE_NEMOTRON3_DIAR_PRESET_VERY_HIGH_LATENCY = 1
TRANSCRIBE_NEMOTRON3_DIAR_PRESET_LOW_LATENCY = 2
TRANSCRIBE_NEMOTRON3_DIAR_PRESET_VERY_LOW_LATENCY = 3
TRANSCRIBE_NEMOTRON3_DIAR_PRESET_ULTRA_LOW_LATENCY = 4
TRANSCRIBE_SORTFORMER_PRESET_DEFAULT = 0
TRANSCRIBE_SORTFORMER_PRESET_VERY_HIGH_LATENCY = 1
TRANSCRIBE_SORTFORMER_PRESET_HIGH_LATENCY = 2
Expand All @@ -150,6 +155,7 @@
TRANSCRIBE_BACKEND_MASK_ROCM = 16
TRANSCRIBE_BACKEND_MASK_VULKAN = 4
TRANSCRIBE_EXT_KIND_MOONSHINE_STREAMING_STREAM = 1414746957
TRANSCRIBE_EXT_KIND_NEMOTRON3_DIAR_DIARIZE = 1145320270
TRANSCRIBE_EXT_KIND_PARAKEET_BUFFERED_STREAM = 1396853584
TRANSCRIBE_EXT_KIND_PARAKEET_STREAM = 1414744912
TRANSCRIBE_EXT_KIND_SORTFORMER_DIARIZE = 1380206163
Expand Down Expand Up @@ -207,6 +213,8 @@ class transcribe_langid_candidate(_c.Structure):
pass
class transcribe_moonshine_streaming_stream_ext(_c.Structure):
pass
class transcribe_nemotron3_diar_diarize_ext(_c.Structure):
pass
class transcribe_parakeet_stream_ext(_c.Structure):
pass
class transcribe_parakeet_buffered_stream_ext(_c.Structure):
Expand Down Expand Up @@ -263,6 +271,7 @@ class transcribe_whisper_chunk_trace(_c.Structure):
transcribe_langid_result._fields_ = [("struct_size", _c.c_uint64), ("n_candidates", _c.c_int32), ("allowed_mass", _c.c_float)]
transcribe_langid_candidate._fields_ = [("struct_size", _c.c_uint64), ("index", _c.c_int32), ("code", _c.c_char_p), ("name", _c.c_char_p), ("p", _c.c_float), ("logit", _c.c_float)]
transcribe_moonshine_streaming_stream_ext._fields_ = [("ext", transcribe_ext), ("min_decode_interval_ms", _c.c_int32)]
transcribe_nemotron3_diar_diarize_ext._fields_ = [("ext", transcribe_ext), ("preset", _c.c_int)]
transcribe_parakeet_stream_ext._fields_ = [("ext", transcribe_ext), ("att_context_right", _c.c_int32)]
transcribe_parakeet_buffered_stream_ext._fields_ = [("ext", transcribe_ext), ("left_ms", _c.c_int32), ("chunk_ms", _c.c_int32), ("right_ms", _c.c_int32)]
transcribe_sortformer_diarize_ext._fields_ = [("ext", transcribe_ext), ("preset", _c.c_int)]
Expand Down Expand Up @@ -344,6 +353,7 @@ class transcribe_whisper_chunk_trace(_c.Structure):
'transcribe_langid_result': {'size': 16, 'align': 8, 'offsets': {'struct_size': 0, 'n_candidates': 8, 'allowed_mass': 12}},
'transcribe_langid_candidate': {'size': 40, 'align': 8, 'offsets': {'struct_size': 0, 'index': 8, 'code': 16, 'name': 24, 'p': 32, 'logit': 36}},
'transcribe_moonshine_streaming_stream_ext': {'size': 24, 'align': 8, 'offsets': {'ext': 0, 'min_decode_interval_ms': 16}},
'transcribe_nemotron3_diar_diarize_ext': {'size': 24, 'align': 8, 'offsets': {'ext': 0, 'preset': 16}},
'transcribe_parakeet_stream_ext': {'size': 24, 'align': 8, 'offsets': {'ext': 0, 'att_context_right': 16}},
'transcribe_parakeet_buffered_stream_ext': {'size': 32, 'align': 8, 'offsets': {'ext': 0, 'left_ms': 16, 'chunk_ms': 20, 'right_ms': 24}},
'transcribe_sortformer_diarize_ext': {'size': 24, 'align': 8, 'offsets': {'ext': 0, 'preset': 16}},
Expand Down Expand Up @@ -534,6 +544,8 @@ def configure(lib):
lib.transcribe_n_tokens.argtypes = [_c.c_void_p]
lib.transcribe_n_words.restype = _c.c_int
lib.transcribe_n_words.argtypes = [_c.c_void_p]
lib.transcribe_nemotron3_diar_diarize_ext_init.restype = None
lib.transcribe_nemotron3_diar_diarize_ext_init.argtypes = [_c.POINTER(transcribe_nemotron3_diar_diarize_ext)]
lib.transcribe_open.restype = _c.c_int
lib.transcribe_open.argtypes = [_c.c_char_p, _c.POINTER(transcribe_model_load_params), _c.POINTER(transcribe_session_params), _c.POINTER(_c.c_void_p)]
lib.transcribe_parakeet_buffered_stream_ext_init.restype = None
Expand Down
15 changes: 15 additions & 0 deletions bindings/python/tests/test_family_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
t.ParakeetStreamOptions,
t.ParakeetBufferedStreamOptions,
t.SortformerDiarizeOptions,
t.Nemotron3DiarDiarizeOptions,
t.VoxtralRealtimeStreamOptions,
]

Expand Down Expand Up @@ -87,6 +88,20 @@ def test_sortformer_diarize_preset_maps_to_enum_value():
assert default.preset == _generated.TRANSCRIBE_SORTFORMER_PRESET_DEFAULT


def test_nemotron3_diar_diarize_preset_maps_to_enum_value():
cls = t.Nemotron3DiarDiarizeOptions
assert cls._slot == "diarize_run"
assert cls._kind == _generated.TRANSCRIBE_EXT_KIND_NEMOTRON3_DIAR_DIARIZE
built = cls(preset="ultra_low_latency")._build()
assert built.preset == _generated.TRANSCRIBE_NEMOTRON3_DIAR_PRESET_ULTRA_LOW_LATENCY
assert cls()._build().preset == _generated.TRANSCRIBE_NEMOTRON3_DIAR_PRESET_DEFAULT


def test_nemotron3_diar_unknown_preset_rejected():
with pytest.raises(ValueError, match="preset"):
t.Nemotron3DiarDiarizeOptions(preset="high_latency") # type: ignore[arg-type]


# --- model-gated: resolve_family validation + a real extension run ----------


Expand Down
42 changes: 40 additions & 2 deletions bindings/rust/sys/src/transcribe_sys.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @generated by `cargo xtask bindgen` from include/transcribe/extensions.h
// DO NOT EDIT BY HAND. Regenerate: `cargo xtask bindgen`.
// Pinned to include/transcribe.abihash = d550d6960224e260
// Pinned to include/transcribe.abihash = fa695c0a3ae06edd

/// The public-ABI digest these bindings were generated against
/// (sha256/16 over the normalized FFI surface). The load-time version
/// gate and the CI drift check both anchor on this value.
pub const PUBLIC_HEADER_HASH: &str = "d550d6960224e260";
pub const PUBLIC_HEADER_HASH: &str = "fa695c0a3ae06edd";

/* automatically generated by rust-bindgen 0.72.1 */

Expand All @@ -17,6 +17,7 @@ pub const TRANSCRIBE_BACKEND_MASK_ROCM: u32 = 16;
pub const TRANSCRIBE_BACKEND_MASK_OTHER: u32 = 2147483648;
pub const TRANSCRIBE_BACKEND_MASK_ALL: u32 = 4294967295;
pub const TRANSCRIBE_EXT_KIND_MOONSHINE_STREAMING_STREAM: u32 = 1414746957;
pub const TRANSCRIBE_EXT_KIND_NEMOTRON3_DIAR_DIARIZE: u32 = 1145320270;
pub const TRANSCRIBE_EXT_KIND_PARAKEET_STREAM: u32 = 1414744912;
pub const TRANSCRIBE_EXT_KIND_PARAKEET_BUFFERED_STREAM: u32 = 1396853584;
pub const TRANSCRIBE_EXT_KIND_SORTFORMER_DIARIZE: u32 = 1380206163;
Expand Down Expand Up @@ -1528,6 +1529,43 @@ unsafe extern "C" {
ext: *mut transcribe_moonshine_streaming_stream_ext,
);
}
impl transcribe_nemotron3_diar_preset {
pub const TRANSCRIBE_NEMOTRON3_DIAR_PRESET_DEFAULT: transcribe_nemotron3_diar_preset =
transcribe_nemotron3_diar_preset(0);
pub const TRANSCRIBE_NEMOTRON3_DIAR_PRESET_VERY_HIGH_LATENCY: transcribe_nemotron3_diar_preset =
transcribe_nemotron3_diar_preset(1);
pub const TRANSCRIBE_NEMOTRON3_DIAR_PRESET_LOW_LATENCY: transcribe_nemotron3_diar_preset =
transcribe_nemotron3_diar_preset(2);
pub const TRANSCRIBE_NEMOTRON3_DIAR_PRESET_VERY_LOW_LATENCY: transcribe_nemotron3_diar_preset =
transcribe_nemotron3_diar_preset(3);
pub const TRANSCRIBE_NEMOTRON3_DIAR_PRESET_ULTRA_LOW_LATENCY: transcribe_nemotron3_diar_preset =
transcribe_nemotron3_diar_preset(4);
}
#[repr(transparent)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct transcribe_nemotron3_diar_preset(pub ::std::os::raw::c_uint);
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct transcribe_nemotron3_diar_diarize_ext {
pub ext: transcribe_ext,
pub preset: transcribe_nemotron3_diar_preset,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of transcribe_nemotron3_diar_diarize_ext"]
[::std::mem::size_of::<transcribe_nemotron3_diar_diarize_ext>() - 24usize];
["Alignment of transcribe_nemotron3_diar_diarize_ext"]
[::std::mem::align_of::<transcribe_nemotron3_diar_diarize_ext>() - 8usize];
["Offset of field: transcribe_nemotron3_diar_diarize_ext::ext"]
[::std::mem::offset_of!(transcribe_nemotron3_diar_diarize_ext, ext) - 0usize];
["Offset of field: transcribe_nemotron3_diar_diarize_ext::preset"]
[::std::mem::offset_of!(transcribe_nemotron3_diar_diarize_ext, preset) - 16usize];
};
unsafe extern "C" {
pub fn transcribe_nemotron3_diar_diarize_ext_init(
ext: *mut transcribe_nemotron3_diar_diarize_ext,
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct transcribe_parakeet_stream_ext {
Expand Down
31 changes: 31 additions & 0 deletions bindings/rust/transcribe-cpp-types/src/family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,44 @@ pub struct SortformerDiarizeOptions {
pub preset: Option<SortformerPreset>,
}

/// Nemotron-3-Diarization streaming operating point (latency / accuracy
/// trade-off). Latency = chunk + lookahead; `Default` keeps the
/// GGUF-shipped configuration (= `VeryHighLatency`).
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Nemotron3DiarPreset {
#[default]
Default,
/// 30.4 s; the offline-file operating point.
VeryHighLatency,
/// 1.04 s.
LowLatency,
/// 0.64 s.
VeryLowLatency,
/// 0.32 s (compute-heavy per audio second).
UltraLowLatency,
}

/// Nemotron-3-Diarization diarize-extension knobs (diarize-run slot). `None`
/// keeps the family default (the GGUF-shipped cfg).
#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(default)
)]
pub struct Nemotron3DiarDiarizeOptions {
pub preset: Option<Nemotron3DiarPreset>,
}

/// A family extension for the diarize-run slot
/// (`transcribe_cpp::DiarizeSession::run`).
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DiarizeExtension {
Sortformer(SortformerDiarizeOptions),
Nemotron3Diar(Nemotron3DiarDiarizeOptions),
}

/// A family extension for the run slot (offline `run`/`run_batch`).
Expand Down
6 changes: 3 additions & 3 deletions bindings/rust/transcribe-cpp-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ pub use backend::{BackendMask, DeviceType};
pub use diarize::{DiarizeInfo, DiarizeOptions, DiarizeSessionOptions};
pub use error::{ErrorKind, ErrorReport};
pub use family::{
DiarizeExtension, MoonshineStreamingOptions, ParakeetBufferedStreamOptions,
ParakeetStreamOptions, RunExtension, SortformerDiarizeOptions, SortformerPreset,
StreamExtension, VoxtralRealtimeStreamOptions, WhisperRunOptions,
DiarizeExtension, MoonshineStreamingOptions, Nemotron3DiarDiarizeOptions, Nemotron3DiarPreset,
ParakeetBufferedStreamOptions, ParakeetStreamOptions, RunExtension, SortformerDiarizeOptions,
SortformerPreset, StreamExtension, VoxtralRealtimeStreamOptions, WhisperRunOptions,
};
pub use langid::{LangIdCandidate, LangIdInfo, LangIdOptions, LangIdResult, LangIdSessionOptions};
pub use model::{Capabilities, SessionLimits, SessionOptions};
Expand Down
36 changes: 35 additions & 1 deletion bindings/rust/transcribe-cpp/src/family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use std::ffi::CString;

use transcribe_cpp_sys as sys;
use transcribe_cpp_types::{DiarizeExtension, RunExtension, SortformerPreset, StreamExtension};
use transcribe_cpp_types::{
DiarizeExtension, Nemotron3DiarPreset, RunExtension, SortformerPreset, StreamExtension,
};

use crate::error::{Error, Result};
use crate::types::ToRaw;
Expand Down Expand Up @@ -45,9 +47,30 @@ impl ToRaw for SortformerPreset {
}
}

impl ToRaw for Nemotron3DiarPreset {
type Raw = sys::transcribe_nemotron3_diar_preset;
fn to_raw(self) -> Self::Raw {
use sys::transcribe_nemotron3_diar_preset as P;
match self {
Nemotron3DiarPreset::Default => P::TRANSCRIBE_NEMOTRON3_DIAR_PRESET_DEFAULT,
Nemotron3DiarPreset::VeryHighLatency => {
P::TRANSCRIBE_NEMOTRON3_DIAR_PRESET_VERY_HIGH_LATENCY
}
Nemotron3DiarPreset::LowLatency => P::TRANSCRIBE_NEMOTRON3_DIAR_PRESET_LOW_LATENCY,
Nemotron3DiarPreset::VeryLowLatency => {
P::TRANSCRIBE_NEMOTRON3_DIAR_PRESET_VERY_LOW_LATENCY
}
Nemotron3DiarPreset::UltraLowLatency => {
P::TRANSCRIBE_NEMOTRON3_DIAR_PRESET_ULTRA_LOW_LATENCY
}
}
}
}

/// Owns a materialized diarize-slot C extension struct.
pub(crate) enum DiarizeExtRaw {
Sortformer(Box<sys::transcribe_sortformer_diarize_ext>),
Nemotron3Diar(Box<sys::transcribe_nemotron3_diar_diarize_ext>),
}

impl DiarizeExtRaw {
Expand All @@ -57,6 +80,10 @@ impl DiarizeExtRaw {
(&**e) as *const sys::transcribe_sortformer_diarize_ext
as *const sys::transcribe_ext
}
DiarizeExtRaw::Nemotron3Diar(e) => {
(&**e) as *const sys::transcribe_nemotron3_diar_diarize_ext
as *const sys::transcribe_ext
}
}
}
}
Expand All @@ -71,6 +98,13 @@ impl Materialize for DiarizeExtension {
set(&mut e.preset, o.preset.map(ToRaw::to_raw));
DiarizeExtRaw::Sortformer(Box::new(e))
}
DiarizeExtension::Nemotron3Diar(o) => {
let mut e: sys::transcribe_nemotron3_diar_diarize_ext =
unsafe { std::mem::zeroed() };
unsafe { sys::transcribe_nemotron3_diar_diarize_ext_init(&mut e) };
set(&mut e.preset, o.preset.map(ToRaw::to_raw));
DiarizeExtRaw::Nemotron3Diar(Box::new(e))
}
other => return Err(unmapped(other)),
})
}
Expand Down
13 changes: 7 additions & 6 deletions bindings/rust/transcribe-cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ pub use transcribe_cpp_types::{
Backend, BackendMask, Capabilities, CommitPolicy, DeviceType, Diarize, DiarizeExtension,
DiarizeInfo, DiarizeOptions, DiarizeSessionOptions, ErrorKind, ErrorReport, ExtSlot, Feature,
Itn, KvType, LangIdCandidate, LangIdInfo, LangIdOptions, LangIdResult, LangIdSessionOptions,
MoonshineStreamingOptions, ParakeetBufferedStreamOptions, ParakeetStreamOptions, Pnc, Role,
Roles, RunExtension, RunOptions, Segment, SessionLimits, SessionOptions,
SortformerDiarizeOptions, SortformerPreset, SpeakerSegment, StreamExtension, StreamOptions,
StreamState, StreamText, StreamUpdate, Task, TimestampKind, Timings, Token, Transcript,
TurnInfo, TurnOptions, TurnResult, TurnSessionOptions, VadInfo, VadOptions, VadResult,
VadSegment, VadSessionOptions, VoxtralRealtimeStreamOptions, WhisperRunOptions, Word,
MoonshineStreamingOptions, Nemotron3DiarDiarizeOptions, Nemotron3DiarPreset,
ParakeetBufferedStreamOptions, ParakeetStreamOptions, Pnc, Role, Roles, RunExtension,
RunOptions, Segment, SessionLimits, SessionOptions, SortformerDiarizeOptions, SortformerPreset,
SpeakerSegment, StreamExtension, StreamOptions, StreamState, StreamText, StreamUpdate, Task,
TimestampKind, Timings, Token, Transcript, TurnInfo, TurnOptions, TurnResult,
TurnSessionOptions, VadInfo, VadOptions, VadResult, VadSegment, VadSessionOptions,
VoxtralRealtimeStreamOptions, WhisperRunOptions, Word,
};

pub use backend::{
Expand Down
2 changes: 2 additions & 0 deletions bindings/rust/transcribe-cpp/tests/reexports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ reexported!(
Segment,
SessionLimits,
SessionOptions,
Nemotron3DiarDiarizeOptions,
Nemotron3DiarPreset,
SortformerDiarizeOptions,
SortformerPreset,
SpeakerSegment,
Expand Down
Loading
Loading