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    /// Invalid voice data
13    #[error(
14        "Invalid voice data: {0}\nContext: {1}\nSuggestion: Ensure voice embeddings are properly downloaded from HuggingFace"
15    )]
16    InvalidVoiceData(String, String),
17
18    /// Audio generation failed
19    #[error(
20        "Audio generation failed: {0}\nInput text length: {1} characters\nVoice: {2}\nSuggestion: Try shorter text or check model initialization"
21    )]
22    GenerationFailed(String, usize, String),
23
24    /// Streaming not supported
25    #[error(
26        "Streaming not supported by this provider\nProvider: {0}\nSuggestion: Use generate_speech() instead of generate_speech_stream()"
27    )]
28    StreamingNotSupported(String),
29
30    /// IO error
31    #[error(
32        "IO error during TTS operation: {0}\nOperation: {1}\nPath: {2}\nSuggestion: Check file permissions and disk space"
33    )]
34    IoError(std::io::Error, String, String),
35
36    /// Model not found
37    #[error(
38        "Model not found: '{0}'\nModel path: {1}\nSuggestion: Ensure model is downloaded from HuggingFace. Check HUGGINGFACE_TOKEN environment variable"
39    )]
40    ModelNotFound(String, String),
41
42    /// Other errors
43    #[error("TTS error: {0}\nContext: {1}")]
44    Other(String, String),
45}
46
47/// Result type for TTS operations
48pub type TTSResult<T> = Result<T, TTSError>;
49
50/// STT-related errors
51#[derive(Error, Debug)]
52pub enum STTError {
53    /// Provider-specific error
54    #[error(
55        "STT provider error: {0}\nProvider: {1}\nDetails: This error originated from the STT provider implementation"
56    )]
57    ProviderError(String, String),
58
59    /// Transcription failed
60    #[error(
61        "Transcription failed: {0}\nAudio duration: {1}s\nSample rate: {2}Hz\nSuggestion: Check audio quality or try a different model"
62    )]
63    TranscriptionFailed(String, f32, u32),
64
65    /// Streaming not supported
66    #[error(
67        "Streaming not supported by this provider\nProvider: {0}\nSuggestion: Use transcribe() instead of transcribe_stream()"
68    )]
69    StreamingNotSupported(String),
70
71    /// Invalid audio format
72    #[error(
73        "Invalid audio format: {0}\nExpected sample rate: {1}Hz, Got: {2}Hz\nExpected channels: {3}, Got: {4}\nSuggestion: Resample audio to the correct format"
74    )]
75    InvalidAudioFormat(String, u32, u32, u16, u16),
76
77    /// IO error
78    #[error(
79        "IO error during STT operation: {0}\nOperation: {1}\nPath: {2}\nSuggestion: Check file permissions and disk space"
80    )]
81    IoError(std::io::Error, String, String),
82
83    /// Model not found
84    #[error(
85        "Model not found: '{0}'\nModel path: {1}\nSuggestion: Ensure model is downloaded from HuggingFace"
86    )]
87    ModelNotFound(String, String),
88
89    /// Other errors
90    #[error("STT error: {0}\nContext: {1}")]
91    Other(String, String),
92}
93
94/// Result type for STT operations
95pub type STTResult<T> = Result<T, STTError>;