Skip to main content

autoagents_speech/
provider.rs

1use crate::{AudioChunk, AudioFormat, ModelInfo, SpeechRequest, SpeechResponse, TTSResult};
2use async_trait::async_trait;
3use futures::Stream;
4use std::pin::Pin;
5
6/// Marker Trait for TTS providers
7///
8/// This trait combines all TTS capabilities into a single provider interface.
9/// Providers should implement this marker trait along with the specific capability traits.
10#[async_trait]
11pub trait TTSProvider: TTSSpeechProvider + TTSModelsProvider + Send + Sync {}
12
13/// Trait for TTS speech generation capabilities
14#[async_trait]
15pub trait TTSSpeechProvider: Send + Sync {
16    /// Generate speech from text (required)
17    ///
18    /// # Arguments
19    /// * `request` - Speech generation request with text, voice, and format
20    ///
21    /// # Returns
22    /// Speech response with audio data and metadata
23    async fn generate_speech(&self, request: SpeechRequest) -> TTSResult<SpeechResponse>;
24
25    /// Generate speech as a stream (optional)
26    ///
27    /// # Arguments
28    /// * `request` - Speech generation request
29    ///
30    /// # Returns
31    /// Stream of audio chunks
32    async fn generate_speech_stream<'a>(
33        &'a self,
34        _request: SpeechRequest,
35    ) -> TTSResult<Pin<Box<dyn Stream<Item = TTSResult<AudioChunk>> + Send + 'a>>> {
36        // Default implementation: not supported
37        Err(crate::error::TTSError::StreamingNotSupported(
38            "Not Supported".to_string(),
39        ))
40    }
41
42    /// Check if streaming is supported (default: false)
43    fn supports_streaming(&self) -> bool {
44        false
45    }
46
47    /// Get supported audio formats (default: WAV only)
48    fn supported_formats(&self) -> Vec<AudioFormat> {
49        vec![AudioFormat::Wav]
50    }
51
52    /// Get default sample rate
53    fn default_sample_rate(&self) -> u32 {
54        24000
55    }
56}
57
58/// Trait for TTS model management capabilities
59#[async_trait]
60pub trait TTSModelsProvider: Send + Sync {
61    /// List available models (optional)
62    ///
63    /// # Returns
64    /// List of available model information
65    async fn list_models(&self) -> TTSResult<Vec<ModelInfo>> {
66        Ok(vec![])
67    }
68
69    /// Get current model information (required)
70    ///
71    /// # Returns
72    /// Current model information
73    fn get_current_model(&self) -> ModelInfo;
74
75    /// Get supported languages
76    fn supported_languages(&self) -> Vec<String> {
77        vec!["en".to_string()]
78    }
79}