mod async_openai_self;
mod groq;
pub use self::async_openai_self::OpenAIProvider;
pub use self::groq::GroqProvider;
use anyhow::Result;
use async_trait::async_trait;
use tracing::{debug, info, warn};
#[async_trait]
pub trait TranscriptionProvider {
fn name(&self) -> &'static str;
fn min_chunk_duration(&self) -> std::time::Duration {
std::time::Duration::from_secs(5) }
async fn transcribe(&self, audio_data: &[u8]) -> Result<String>;
}
pub struct MockProvider;
impl MockProvider {
pub fn new() -> Self {
Self {}
}
}
#[async_trait]
impl TranscriptionProvider for MockProvider {
fn name(&self) -> &'static str {
"Mock"
}
fn min_chunk_duration(&self) -> std::time::Duration {
std::time::Duration::from_secs(5)
}
async fn transcribe(&self, _audio_data: &[u8]) -> Result<String> {
info!("Starting mock transcription");
debug!("Simulating processing delay");
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
let result = "This is a mock transcription result.".to_string();
info!("Mock transcription completed");
Ok(result)
}
}
pub async fn create_provider(provider_name: &str) -> Box<dyn TranscriptionProvider + Send + Sync> {
debug!("Creating provider: {}", provider_name);
match provider_name.to_lowercase().as_str() {
"openai" => {
debug!("Initializing OpenAI provider");
Box::new(OpenAIProvider::new().await)
}
"groq" => {
debug!("Initializing Groq provider");
Box::new(GroqProvider::new().await)
}
"mock" => {
debug!("Initializing Mock provider");
Box::new(MockProvider::new())
}
_ => {
warn!("Unknown provider '{}', using mock provider", provider_name);
Box::new(MockProvider::new())
}
}
}