Expand description
Core TTS engine trait.
Traits§
- TtsEngine
- Trait that every TTS engine must implement.
Functions§
- estimate_
word_ boundaries - Estimate word boundaries using word-length-adjusted timing with an
inter-sentence pause. Originally mirroring Swift’s
WordTimingEstimator, since extended (sentence gaps) beyond it. - estimate_
word_ boundaries_ with_ wpm - Estimate word boundaries with configurable words per minute. Abbreviation caveat: token-level detection means “Mr.” / “e.g.” also get the sentence gap — an accepted trade-off for an estimator.
- preprocess_
speech_ markdown - Convert SpeechMarkdown to SSML when detected, otherwise return the text
unchanged. Returns
(processed_text, is_ssml). - strip_
ssml_ to_ text - Strip all XML/SSML tags from
ssml, returning the plain-text content with collapsed whitespace. Used to convert incoming W3C SSML (fromtts_speak_ssml) to plain text for engines that don’t accept SSML (OpenAI, ElevenLabs, SherpaOnnx, etc.). - syllable_
count - Rough syllable count for duration weighting: contiguous vowel groups (English-centric), every digit spoken individually, minimum one.
- trailing_
pause_ weight - Pause weight AFTER a word, in syllable-equivalents, from its trailing punctuation. Sentence ends breathe longest; commas/semicolons beat.
- unwrap_
voice_ tag - Extract the
nameattribute from a<voice name='...'>(or"...") tag and return the inner SSML content wrapped in a bare<speak>element. - weighted_
boundaries_ scaled - Word boundaries with RELATIVE durations mapped onto a known total
duration (engines that know the audio length but not per-word times —
e.g. qwen3-local). The word shape comes from the syllable/pause
weights; the timeline is linearly rescaled so the last word ends
exactly at
total_secs. Offsets/durations are absolute seconds. - word_
weight - Duration weight of a word in syllable-equivalents: syllables plus a small constant for onsets/codas so “a” is not zero-length.
Type Aliases§
- OnAudio
Callback - Callback for streaming audio chunks.
- OnBoundary
Callback - Callback for word boundary events.
Signature: (word, start_sec, end_sec, byte_offset, byte_len, estimated)
byte_offsetis a byte index into the text as submitted (for SpeechMarkdown input, the caller’s original source — highlighting targets the caller’s string) andbyte_lena byte length. When a word cannot be located (normalization mismatch, punctuation artifact), the callback receives the last known offset held (0 if nothing matched yet) withbyte_len-1 — not a -1 offset.estimatedis true for proportional estimates (unpatched voices, wpm model), false for measured timings (cloud provider timings). - OnEnd
Callback - Callback for speech-finished events.
- OnError
Callback - Callback for error events.
- OnMark
Callback - Callback for SSML mark/bookmark events.
Signature: (name, start_sec, end_sec, char_offset)
char_offset is -1 when the engine doesn’t report it. Engines that
estimated) audio position; consumers map it to their bookmark event
(SAPI
SPEI_TTS_BOOKMARK, SSIP index marks). - OnStart
Callback - Callback for speech-started events.