Skip to main content

autoagents_speech/
error.rs

1use thiserror::Error;
2
3/// TTS-related errors
4#[derive(Error, Debug)]
5pub enum TTSError {
6    /// Provider-specific error
7    #[error(
8        "TTS provider error: {0}\nProvider: {1}\nDetails: This error originated from the TTS provider implementation"
9    )]
10    ProviderError(String, String),
11
12    /// Voice not found
13    #[error(
14        "Voice not found: '{0}'\nAvailable voices: {1}\nSuggestion: Use list_predefined_voices() to see all available voices"
15    )]
16    VoiceNotFound(String, String),
17
18    /// Invalid voice data
19    #[error(
20        "Invalid voice data: {0}\nContext: {1}\nSuggestion: Ensure voice embeddings are properly downloaded from HuggingFace"
21    )]
22    InvalidVoiceData(String, String),
23
24    /// Audio generation failed
25    #[error(
26        "Audio generation failed: {0}\nInput text length: {1} characters\nVoice: {2}\nSuggestion: Try shorter text or check model initialization"
27    )]
28    GenerationFailed(String, usize, String),
29
30    /// Streaming not supported
31    #[error(
32        "Streaming not supported by this provider\nProvider: {0}\nSuggestion: Use generate_speech() instead of generate_speech_stream()"
33    )]
34    StreamingNotSupported(String),
35
36    /// Format not supported
37    #[error(
38        "Audio format not supported: {0:?}\nProvider: {1}\nSupported formats: {2}\nSuggestion: Use one of the supported formats"
39    )]
40    FormatNotSupported(crate::types::AudioFormat, String, String),
41
42    /// IO error
43    #[error(
44        "IO error during TTS operation: {0}\nOperation: {1}\nPath: {2}\nSuggestion: Check file permissions and disk space"
45    )]
46    IoError(std::io::Error, String, String),
47
48    /// Serialization error
49    #[error(
50        "Serialization error: {0}\nData type: {1}\nSuggestion: Check that data structure is serializable"
51    )]
52    SerializationError(String, String),
53
54    /// Model not found
55    #[error(
56        "Model not found: '{0}'\nModel path: {1}\nSuggestion: Ensure model is downloaded from HuggingFace. Check HUGGINGFACE_TOKEN environment variable"
57    )]
58    ModelNotFound(String, String),
59
60    /// Invalid configuration
61    #[error(
62        "Invalid configuration: {0}\nParameter: {1}\nValid range: {2}\nSuggestion: Review configuration documentation"
63    )]
64    InvalidConfiguration(String, String, String),
65
66    /// Provider not ready
67    #[error(
68        "Provider not ready: {0}\nProvider: {1}\nInitialization state: {2}\nSuggestion: Wait for provider initialization or check logs for errors"
69    )]
70    ProviderNotReady(String, String, String),
71
72    /// Other errors
73    #[error("TTS error: {0}\nContext: {1}")]
74    Other(String, String),
75}
76
77/// Result type for TTS operations
78pub type TTSResult<T> = Result<T, TTSError>;