Skip to main content

kothok_edge_tts/
tts.rs

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