use std::error::Error;
use std::fmt;
#[derive(Debug, Clone)]
pub enum TranscriptionError {
ModelNotAvailable(String),
InferenceError(String),
InvalidAudio(String),
UnsupportedLanguage(String),
BackendNotImplemented(String),
ConfigurationError(String),
IoError(String),
}
impl fmt::Display for TranscriptionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TranscriptionError::ModelNotAvailable(msg) => {
write!(f, "Model not available: {}", msg)
}
TranscriptionError::InferenceError(msg) => {
write!(f, "Inference error: {}", msg)
}
TranscriptionError::InvalidAudio(msg) => {
write!(f, "Invalid audio: {}", msg)
}
TranscriptionError::UnsupportedLanguage(msg) => {
write!(f, "Unsupported language: {}", msg)
}
TranscriptionError::BackendNotImplemented(msg) => {
write!(f, "Backend not implemented: {}", msg)
}
TranscriptionError::ConfigurationError(msg) => {
write!(f, "Configuration error: {}", msg)
}
TranscriptionError::IoError(msg) => {
write!(f, "I/O error: {}", msg)
}
}
}
}
impl Error for TranscriptionError {}
impl From<anyhow::Error> for TranscriptionError {
fn from(err: anyhow::Error) -> Self {
TranscriptionError::InferenceError(err.to_string())
}
}
impl From<std::io::Error> for TranscriptionError {
fn from(err: std::io::Error) -> Self {
TranscriptionError::IoError(err.to_string())
}
}
#[derive(Debug, Clone)]
pub struct TranscriptionResult {
pub text: String,
pub confidence: Option<f32>,
pub detected_language: Option<String>,
}
impl TranscriptionResult {
pub fn new(text: String) -> Self {
Self {
text,
confidence: None,
detected_language: None,
}
}
pub fn with_confidence(text: String, confidence: f32) -> Self {
Self {
text,
confidence: Some(confidence),
detected_language: None,
}
}
}