Expand description
Safe, idiomatic Rust bindings for transcribe.cpp, a C/C++ speech-to-text library built on ggml.
The raw FFI lives in the transcribe-cpp-sys crate
(re-exported as sys); this crate wraps it with owned result types, an
error enum, RAII handles, and a thread-safety model that matches the C
contract.
§Quickstart
use transcribe_cpp::{Model, RunOptions};
let mut session = Model::load("model.gguf")?.session()?;
let pcm: Vec<f32> = vec![/* 16 kHz mono samples in [-1, 1] */];
let result = session.run(&pcm, &RunOptions::default())?;
println!("{}", result.text);§Threading
ModelisSend + Syncand cheap to clone (Arc-backed). The native model is freed only after the lastModelhandle and everySessionderived from it are dropped — in any order.SessionisSendbut notSync; its mutating calls take&mut self, so the type system enforces one-call-at-a-time.- 0.x concurrency: the C library permits at most one in-flight compute
across all sessions of a model,
DiarizeSessions,LangIdSessions andVadSessions included. This crate enforces that with a per-model mutex (held only for the native compute call), so concurrent calls from many sessions queue rather than race. An active ASR stream holds the model’s stream lease; other runs, including VADrun/stream_feed/stream_flush, returnError::Busymeanwhile. A VAD stream does not take the lease. For real parallelism, use oneModelper worker today.
§ABI verification
The per-field struct-layout check that the ctypes binding performs is
waived here: bindgen takes every struct’s layout from a real compiler at
generation time, so the generated FFI cannot disagree with the headers it
was built against. The load-time base-version lock (see Model::load) is
retained.
Re-exports§
pub use transcribe_cpp_sys as sys;
Structs§
- Backend
Mask - Backend kinds allowed to register in this process. A backend outside the
mask never runs any code, so a broken GPU driver can be kept out of a
worker entirely. CPU is always allowed;
TRANSCRIBE_BACKENDScan only narrow the mask. - Cancel
Token - A clonable cancellation handle. Clones share one underlying flag, so a worker thread can hold a clone and cancel a run executing on another thread.
- Capabilities
- Immutable, model-level capabilities read from GGUF metadata.
- Device
- One registered compute device.
- Diarize
Info - Static facts about a diarization model (
Model::diarize_info). - Diarize
Options - Per-run diarization parameters.
- Diarize
Session - A diarization session.
- Diarize
Session Options - Options for creating a diarization session.
- Error
Report - An owned, plain-data snapshot of an
Error: what crosses a process or IPC boundary (e.g. a Tauri command’s error). - Lang
IdCandidate - One ranked label.
codeis the model’s own label ("en","iw"). - Lang
IdInfo - Static facts about a language ID model (
Model::langid_info). - Lang
IdOptions - Per-run language ID parameters.
- Lang
IdResult - The result of one
LangIdSession::run. - Lang
IdSession - A language ID session.
- Lang
IdSession Options - Options for creating a language ID session.
- Model
- A loaded transcription model.
- Model
Options - Options for loading a model.
- Moonshine
Streaming Options - Moonshine-streaming stream-extension knobs (stream slot).
- Parakeet
Buffered Stream Options - Parakeet chunked-attention buffered streaming knobs (stream slot).
- Parakeet
Stream Options - Parakeet cache-aware streaming knobs (stream slot).
- Roles
- The set of
Roles a model serves (Model::roles). - RunOptions
- Per-run parameters.
- Segment
- One segment row. Times are milliseconds relative to the original audio.
- Session
- A transcription session.
- Session
Limits - Per-session effective limits.
- Session
Options - Options for creating a session.
- Sortformer
Diarize Options - Sortformer diarize-extension knobs (diarize-run slot).
Nonekeeps the family default (the GGUF-shipped cfg). - Speaker
Segment - One diarized speaker turn. Zero times mean the model attributed text but
did not provide turn timing;
pis NaN when unavailable. - Stream
- An active streaming run, borrowed from a
Session. - Stream
Options - Options for beginning a stream.
- Stream
Text - A UI-facing snapshot of the stream’s text, fully owned.
- Stream
Update - Per-call change metadata from
feed/finalize. - Timings
- Per-run stage timings, in milliseconds. Zero means “unknown / not measured”.
- Token
- One token row.
pis a per-token confidence hint (NaN when the family produces none); its exact meaning is family-specific. - Transcript
- A fully-materialized transcription result.
- VadInfo
- Static facts about a VAD model (
Model::vad_info). - VadOptions
- Probabilities -> speech segments (
VadSession::runonly). Fields and defaults are those of Silero’sget_speech_timestamps. - VadResult
- The result of one
VadSession::run,VadSession::stream_feedorVadSession::stream_flush. - VadSegment
- One speech segment, in samples of the run’s input:
[start, end). - VadSession
- A VAD session.
- VadSession
Options - Options for creating a VAD session.
- Voxtral
Realtime Stream Options - Voxtral-realtime streaming knobs (stream slot).
- Whisper
RunOptions - Whisper run-extension knobs (run slot): initial prompt, temperature
fallback, and decode thresholds.
Nonekeeps the family default.initial_promptcannot be combined withRunOptions::vocabulary/prompt. - Word
- One word row.
Enums§
- AbiStruct
- A public ABI struct, for size/alignment introspection.
- Backend
- Which compute backend to request when loading a model.
- Commit
Policy - When the UI-facing committed text grows during a stream.
- Device
Type - ggml’s vendor-agnostic class for a compute device, orthogonal to
Device::kind(which carries the vendor). Backends report this classification themselves, so use it as a runtime hint rather than a portable hardware-memory taxonomy. - Diarize
- Speaker-attribution runtime toggle.
- Diarize
Extension - A family extension for the diarize-run slot
(
DiarizeSession::run). - Error
- Everything that can go wrong talking to the native library.
- Error
Kind - The category of an
Error, without its payload. One kind per variant. - ExtSlot
- The slot a family extension is pointed at.
- Feature
- A yes/no model capability probe (
transcribe_model_supports). - Itn
- Inverse-text-normalization runtime toggle.
- KvType
- K/V activation precision for the decoder’s flash-attention path.
- Pnc
- Punctuation + capitalization runtime toggle.
- Role
- A kind of work a model can do (
transcribe_role). - RunExtension
- A family extension for the run slot (offline
run/run_batch). - Sortformer
Preset - Sortformer streaming operating point (latency / accuracy trade-off).
The menu is discrete (jointly-tuned bundles), not a latency dial;
Defaultkeeps the GGUF-shipped checkpoint configuration. - Stream
Extension - A family extension for the stream slot.
- Stream
State - Stream lifecycle state.
- Task
- The task a run performs.
- Timestamp
Kind - Requested (or returned) timestamp granularity.
Functions§
- abi_
struct_ align - The native library’s
alignoffor a public ABI struct, or 0 if unknown. - abi_
struct_ size - The native library’s
sizeoffor a public ABI struct, or 0 if unknown. - allowed_
backends - The effective mask:
init_backends_with’s (ALL until then) narrowed byTRANSCRIBE_BACKENDS. - backend_
available - Whether a backend request can be satisfied by some registered device. This
is the probe to turn
Backend::Vulkanon a machine without Vulkan into a clear error instead of a failed model load. Do not race this query withinit_backendsorinit_backends_default. - compiled_
version - The base version string this crate’s bindings were built against.
- device_
count - The number of compute devices currently registered.
- devices
- Every registered compute device.
- disable_
logging - Silence the native library entirely (drops both library and ggml messages, including the stderr default). Call once at startup.
- header_
hash - The public-ABI digest the committed bindings were generated against.
- init_
backends - Load backend modules from
dir(dynamic builds) and register their devices. A no-op in static builds. Call once, before the first model load. - init_
backends_ default - Load the backend modules the way the build expects, with no caller-supplied path.
- init_
backends_ with init_backends/init_backends_default(dir=None) with an allowed-backend mask. The mask is fixed at first backend registration; call this first, once per process. A later call with a different effective mask returnscrate::Error::Backend.- init_
logging - Route native + ggml diagnostics into the
logcrate. Call once at startup, before loading models. - transcribe
- Convenience: load a model, transcribe one PCM buffer, and return the result.
- version
- The
MAJOR.MINOR.PATCHversion string of the linked native library. - version_
commit - The short git commit the native library was built from (or “unknown”).
Type Aliases§
- Result
- Convenience alias for results from this crate.