Skip to main content

Crate rust_tts_wrapper

Crate rust_tts_wrapper 

Source
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 by cloud).
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§

tts_ctx

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 text asynchronously using the engine in ctx.
tts_speak_ssml
Speak pre-built SSML using the engine in ctx.
tts_speak_sync
Speak text synchronously (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_bytes and its length to *out_len. Caller must free with tts_free_bytes. Returns 0 on success, -1 on failure.

Type Aliases§

CAudioCb
Opaque context holding an engine instance and its per-instance settings.
CBoundaryCb
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. estimated is 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).
CErrorCb
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.
CVisemeCb
CVoidCb