Skip to main content

Module engine

Module engine 

Source
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 (from tts_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 name attribute 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§

OnAudioCallback
Callback for streaming audio chunks.
OnBoundaryCallback
Callback for word boundary events. Signature: (word, start_sec, end_sec, byte_offset, byte_len, estimated) byte_offset is a byte index into the text as submitted (for SpeechMarkdown input, the caller’s original source — highlighting targets the caller’s string) and byte_len a 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) with byte_len -1 — not a -1 offset. estimated is true for proportional estimates (unpatched voices, wpm model), false for measured timings (cloud provider timings).
OnEndCallback
Callback for speech-finished events.
OnErrorCallback
Callback for error events.
OnMarkCallback
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).
OnStartCallback
Callback for speech-started events.