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
run/stream across all sessions of a model. 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. 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§
- 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.
- 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).
- 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.
- 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.
- 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. - 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.
- Error
- Everything that can go wrong talking to the native library.
- 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.
- RunExtension
- A family extension for the run slot (offline
run/run_batch). - 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. - 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. - 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_
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.