blazen_audio_tts/lib.rs
1//! Multi-backend text-to-speech surface for Blazen.
2//!
3//! This crate provides one capability trait — [`TtsBackend`] — that
4//! extends [`blazen_audio::AudioBackend`] with synthesis and voice-
5//! management methods, plus a small set of concrete backends under
6//! [`backends`]:
7//!
8//! - [`backends::anytts::AnyTtsBackend`] — fully local engine via
9//! [`any-tts`](https://crates.io/crates/any-tts) (Kokoro-82M,
10//! `VibeVoice`, Qwen3-TTS). Gated by the `anytts` feature flag.
11//! - [`backends::openai::OpenAiTtsBackend`] — HTTP client for
12//! OpenAI-compatible TTS servers (`/v1/audio/speech` + the de-facto
13//! `/v1/voices/*` extension surface). Gated by the `openai` feature
14//! flag (enabled by default).
15//! - [`backends::piper::PiperBackend`] — reserved slot for a future
16//! Piper-ONNX backend; every method currently returns
17//! [`TtsError::Unsupported`] pending Wave 22 of the PR-AUDIO
18//! restructure.
19//!
20//! Two provider wrappers compose backends with the same surface:
21//!
22//! - [`TtsBackendHandle<B>`] — monomorphized over a concrete backend, used
23//! when the backend choice is fixed at compile time.
24//! - [`DynTtsProvider`] — type-erased `Arc<dyn TtsBackend>`, used by
25//! the manager / pipeline layer.
26//!
27//! # Feature flags
28//!
29//! | Feature | Default | Description |
30//! |-----------|---------|---------------------------------------------------|
31//! | `openai` | yes | Builds [`backends::openai::OpenAiTtsBackend`]. |
32//! | `anytts` | no | Builds [`backends::anytts::AnyTtsBackend`]. |
33//! | `bark` | no | Builds [`backends::bark::BarkBackend`] (Suno-AI |
34//! | | | Bark: 3-stage AR transformer + EnCodec). |
35//! | `f5-tts` | no | Builds [`backends::f5::F5Backend`] (SWivid F5-TTS:|
36//! | | | flow-matching DiT + Vocos vocoder). |
37//! | `engine` | no | **Deprecated** alias for `anytts`; will be |
38//! | | | removed one release after the multi-backend |
39//! | | | restructure ships. |
40
41#![deny(missing_docs)]
42
43pub mod backends;
44mod error;
45mod options;
46mod provider;
47mod traits;
48
49pub use error::TtsError;
50pub use options::{TtsModel, TtsOptions};
51pub use provider::{DynTtsProvider, TtsBackendHandle};
52pub use traits::TtsBackend;
53
54// Re-exports of common backend types so callers don't have to dig
55// through `backends::*` for the most-used names.
56
57#[cfg(feature = "anytts")]
58pub use backends::AnyTtsBackend;
59
60#[cfg(feature = "bark")]
61pub use backends::{BARK_BACKEND_ID_PREFIX, BarkBackend, BarkConfig};
62
63#[cfg(feature = "f5-tts")]
64pub use backends::{F5_BACKEND_ID_PREFIX, F5Backend, F5Config};
65
66#[cfg(feature = "openai")]
67pub use backends::{
68 DEFAULT_MODEL, DEFAULT_RESPONSE_FORMAT, DEFAULT_VOICE, OpenAiTtsBackend, OpenAiTtsConfig,
69 OpenAiTtsSpeechRequest, OpenAiTtsSpeechResponse,
70};
71
72pub use backends::PiperBackend;