Skip to main content

kothok_edge_tts/
tts.rs

1//! The `Engine` trait - the swappable TTS-backend contract.
2//!
3//! `EdgeTts` is the reference implementation.  Consumers that want to mock
4//! the engine in tests or swap in a different provider implement this trait.
5
6use crate::error::TtsError;
7use crate::event::TtsEvent;
8use std::future::Future;
9
10/// A text-to-speech backend.
11///
12/// Implementations must be `Send + Sync` so the engine can live behind an
13/// `Arc` on a worker thread.  The returned future must be `Send` so it can
14/// cross thread boundaries when driven via control channels.
15///
16/// # Arguments
17///
18/// * `text`  - one utterance (callers chunk longer text; the Edge endpoint
19///   caps a single request near ~4 KB).
20/// * `voice` - a full voice short-name, e.g. `"en-US-EmmaMultilingualNeural"`.
21/// * `rate`  - an SSML prosody rate string: `"+0%"`, `"+25%"`, `"-10%"`.
22/// * `lang`  - BCP-47 language tag for the `xml:lang` attribute, e.g. `"en-US"`.
23pub trait Engine: Send + Sync {
24    fn synthesize(
25        &self,
26        text: &str,
27        voice: &str,
28        rate: &str,
29        lang: &str,
30    ) -> impl Future<Output = Result<Vec<TtsEvent>, TtsError>> + Send;
31}