Skip to main content

kothok_edge_tts/
event.rs

1// SPDX-License-Identifier: MIT
2// Copyright (c) 2026 Nayeem Bin Ahsan
3//! Streaming events emitted during a single synthesis turn.
4
5/// One item in the event stream produced by [`crate::Engine::synthesize`].
6///
7/// Events arrive in order. A well-formed turn starts with zero or more
8/// [`Audio`](TtsEvent::Audio) / [`WordBoundary`](TtsEvent::WordBoundary)
9/// events and terminates with exactly one [`TurnEnd`](TtsEvent::TurnEnd).
10#[derive(Debug, Clone)]
11pub enum TtsEvent {
12    /// A chunk of raw MP3 audio bytes (`audio-24khz-48kbitrate-mono-mp3`).
13    /// Concatenate all `Audio` events in order to reconstruct the full
14    /// utterance.
15    Audio(Vec<u8>),
16
17    /// Word-boundary timing metadata for highlight / karaoke effects.
18    /// `offset` and `duration` are in **100-nanosecond ticks** relative to
19    /// the start of the audio stream.
20    WordBoundary {
21        offset: u64,
22        duration: u64,
23        text: String,
24    },
25
26    /// The server signalled `turn.end` - no more audio or metadata will
27    /// arrive for this request.
28    TurnEnd,
29}