- Value objects: ModelId, EngineName, Megabytes, AudioSamples, Segment, Transcript - KonError enum with thiserror - Constants centralised: audio pipeline, VAD, RAM thresholds, inference threading - SpeechToText and TextProcessor provider traits with ProviderRegistry - Unified model registry (Whisper tiny/base/small/medium + Parakeet CTC int8) - Hardware detection: probe_ram, probe_cpu, probe_gpu (stub), probe_os - Recommendation engine: score_model (pure function), rank_recommendations (sorted) - 5 tests passing, clippy clean Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
39 lines
1022 B
Rust
39 lines
1022 B
Rust
use std::sync::Arc;
|
|
|
|
use async_trait::async_trait;
|
|
|
|
use crate::error::Result;
|
|
use crate::types::{AudioSamples, EngineName, Transcript, TranscriptionOptions};
|
|
|
|
/// Any speech-to-text engine implements this trait.
|
|
/// Base types know nothing about their derivatives.
|
|
#[async_trait]
|
|
pub trait SpeechToText: Send + Sync {
|
|
async fn transcribe(
|
|
&self,
|
|
audio: AudioSamples,
|
|
options: &TranscriptionOptions,
|
|
) -> Result<Transcript>;
|
|
|
|
fn name(&self) -> &EngineName;
|
|
|
|
fn is_available(&self) -> bool;
|
|
}
|
|
|
|
/// Any text post-processor implements this trait.
|
|
#[async_trait]
|
|
pub trait TextProcessor: Send + Sync {
|
|
async fn process(&self, text: &str, instruction: &str) -> Result<String>;
|
|
|
|
fn name(&self) -> &EngineName;
|
|
|
|
fn is_available(&self) -> bool;
|
|
}
|
|
|
|
/// Holds the active provider instances. Constructed at startup,
|
|
/// rebuilt when user changes provider in settings.
|
|
pub struct ProviderRegistry {
|
|
pub stt: Arc<dyn SpeechToText>,
|
|
pub text: Option<Arc<dyn TextProcessor>>,
|
|
}
|