Expand description
§rust-tts-wrapper
Cross-platform TTS (Text-to-Speech) wrapper with a C ABI.
Mirrors js-tts-wrapper and SwiftTTSWrapper, supporting 25 engines:
system (speech-dispatcher), AVSpeech (macOS), SAPI (Windows),
Sherpa-ONNX + floravox (local ONNX voices — 1300+ models / ~1,100
languages), and 20 cloud providers.
§Quick start (C)
tts_ctx* ctx = tts_create("system", NULL);
tts_speak(ctx, "Hello world");
tts_destroy(ctx);Re-exports§
pub use engine::TtsEngine;pub use factory::create_engine;pub use sherpaonnx_engine::SherpaOnnxEngine;
Modules§
- boundaries
- Progressive word-boundary firing, shared by the cloud and sherpa-onnx engines.
- cloud_
core - The pure cloud provider shapes shared by the native engine and the
wasm/js crate: sigv4 signing, request builders, response parsers,
provider configs. Enabled by
cloud-core(implied bycloud). - engine
- Core TTS engine trait.
- factory
- Engine factory: create engines by ID and list all registered engines.
- qwen3_
local_ support - Pure helpers for the qwen3-local engine — always compiled (and unit-tested in CI) even when the engine feature is off. Pure (non-FFI) helpers for the qwen3-local engine — ungated so they compile and unit-test in every CI build, even without the C++ library the engine itself links.
- sherpaonnx_
engine - Sherpa-ONNX offline TTS engine with model registry.
- timeline
- Playback timeline: map playback wall-clock time to a text position.
- types
- Shared types used across the crate.
- word_
search - Incremental forward word search over a fixed text, for mapping spoken words back to text positions.
Structs§
Functions§
- tts_
create - Create a new TTS engine instance.
- tts_
destroy - Destroy a TTS context and free all associated resources.
- tts_
free_ bytes - Free a byte buffer returned by
tts_synth_to_bytes. - tts_
free_ engines - Free an engine info array previously returned by
tts_get_engines. - tts_
free_ voices - Free a voice array previously returned by
tts_get_voices. - tts_
get_ engine_ count - Return the number of registered engines.
- tts_
get_ engines - Get the list of available engine descriptors.
- tts_
get_ last_ error - Return the last error message as a C string, or null if none.
- tts_
get_ voices - Retrieve the list of available voices for the engine.
- tts_
pause - Pause in-progress speech.
- tts_
resume - Resume paused speech.
- tts_
set_ on_ audio - Set the callback for streaming audio chunks.
- tts_
set_ on_ boundary - Set the word-boundary callback: cb(word, byte_offset, byte_len, start_s, end_s, estimated, userdata). byte_offset/byte_len are UTF-8 bytes into the spoken text; an unlocatable word holds the last known offset with byte_len -1 (see CBoundaryCb for the full contract and the SAPI UTF-16 exception).
- tts_
set_ on_ end - Set the callback fired when speech completes successfully.
- tts_
set_ on_ error - Set the callback fired when speech fails.
- tts_
set_ on_ mark - Set the mark/bookmark callback: cb(name, char_offset, start_s, end_s, userdata).
Fires for
<mark>/<bookmark>SSML tags at their measured audio - tts_
set_ on_ start - Set the callback fired when speech starts.
- tts_
set_ on_ viseme - Viseme callback for lip-sync / facial animation. cb(viseme_id, audio_offset_sec, userdata)
- tts_
set_ pitch - Set the speech pitch (1.0 = normal).
- tts_
set_ rate - Set the speech rate (1.0 = normal).
- tts_
set_ voice - Set the voice for subsequent speak calls.
- tts_
set_ volume - Set the speech volume (1.0 = normal).
- tts_
speak - Speak
textasynchronously using the engine inctx. - tts_
speak_ ssml - Speak pre-built SSML using the engine in
ctx. - tts_
speak_ sync - Speak
textsynchronously (blocks until complete). - tts_
stop - Stop any in-progress speech.
- tts_
synth_ to_ bytes - Synthesize text to audio bytes without playback.
Writes a heap-allocated buffer to
*out_bytesand its length to*out_len. Caller must free withtts_free_bytes. Returns 0 on success, -1 on failure.
Type Aliases§
- CAudio
Cb - Opaque context holding an engine instance and its per-instance settings.
- CBoundary
Cb - Word-boundary callback:
cb(word, byte_offset, byte_len, start_s, end_s, estimated, userdata).
byte_offset is a UTF-8 byte index into the spoken text, byte_len a
byte length — pair them to slice the text safely. An unlocatable
word holds the last known offset (0 if nothing matched) with
byte_len -1.
estimatedis 1 when the timings are proportional estimates (unpatched voice, wpm model), 0 when measured (cloud provider timings). Exceptions: the Windows SAPI native-boundary path reports UTF-16 code-unit offsets/lengths (the units ISpVoice events provide), and the Azure/Edge WebSocket path passes Azure’s own text.Offset/text.Length through unchanged when Azure supplies them (units per Azure’s documentation; the wrapper’s fallback arithmetic when they are absent is UTF-8 bytes). - CError
Cb - CMarkCb
- Mark/bookmark callback: cb(name, char_offset, start_s, end_s, userdata). char_offset is -1 when unknown; start/end are the measured (or estimated) audio position the mark fires at.
- CViseme
Cb - CVoidCb