Skip to main content

adk_audio/providers/tts/
mod.rs

1//! TTS provider implementations (cloud and native).
2
3#[cfg(feature = "tts")]
4mod cartesia;
5#[cfg(feature = "tts")]
6mod elevenlabs;
7#[cfg(feature = "tts")]
8mod gemini;
9#[cfg(feature = "tts")]
10mod openai;
11
12#[cfg(feature = "qwen3-tts")]
13pub mod qwen3_tts_native;
14
15#[cfg(feature = "tts")]
16pub use cartesia::CartesiaTts;
17#[cfg(feature = "tts")]
18pub use elevenlabs::ElevenLabsTts;
19#[cfg(feature = "tts")]
20pub use gemini::GeminiTts;
21#[cfg(feature = "tts")]
22pub use gemini::SpeakerConfig;
23#[cfg(feature = "tts")]
24pub use openai::OpenAiTts;
25
26#[cfg(feature = "qwen3-tts")]
27pub use qwen3_tts_native::{Qwen3TtsNativeProvider, Qwen3TtsVariant};
28
29/// Shared configuration for cloud TTS providers.
30#[derive(Debug, Clone)]
31pub struct CloudTtsConfig {
32    /// API key for authentication.
33    pub api_key: String,
34    /// Optional base URL override.
35    pub base_url: Option<String>,
36}
37
38impl CloudTtsConfig {
39    /// Create config from an API key.
40    pub fn new(api_key: impl Into<String>) -> Self {
41        Self { api_key: api_key.into(), base_url: None }
42    }
43
44    /// Override the base URL.
45    pub fn with_base_url(mut self, url: impl Into<String>) -> Self {
46        self.base_url = Some(url.into());
47        self
48    }
49}
50
51/// Check an HTTP response status and return an appropriate error.
52#[allow(dead_code)] // Available for provider implementations
53pub(crate) fn check_response(
54    provider: &str,
55    status: reqwest::StatusCode,
56) -> Result<(), crate::error::AudioError> {
57    if status.is_success() {
58        Ok(())
59    } else {
60        Err(crate::error::AudioError::Tts {
61            provider: provider.to_string(),
62            message: format!("HTTP {status}"),
63        })
64    }
65}