stt-cli 0.2.1

Speech to text Cli using Groq API and OpenAI API
// providers.rs
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;

    /// Minimum audio chunk duration required for transcription
    fn min_chunk_duration(&self) -> std::time::Duration {
        std::time::Duration::from_secs(5) // Default to 5 seconds
    }

    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");

        // Simulate 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)
    }
}

/// Create a new transcription provider based on the provider name
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())
        }
    }
}