feat(A.2 #13): replace SpeechBackend enum with Transcriber trait
New crates/transcription/src/transcriber.rs defines a Transcriber trait (Send supertrait for spawn_blocking travel) with TranscriberCapabilities (sample_rate, channels, supports_initial_prompt). TranscriberCapabilities.sample_rate is load-bearing for the upcoming progressive WAV writer (#19). Concrete impls: - SpeechModelAdapter wraps Box<dyn transcribe_rs::SpeechModel + Send> for Parakeet (and any future transcribe-rs-backed engine). - WhisperRsBackend moves its transcribe_sync body into the impl, widening the signature from &self to &mut self so per-call WhisperState can be created cleanly through the trait object. LocalEngine now holds Box<dyn Transcriber + Send>; dispatch in transcribe_sync collapses from a match to a direct call. Adds LocalEngine::capabilities() for the WAV-writer. Cargo feature flag "whisper" (default on) makes whisper-rs, num_cpus, and the whole whisper_rs_backend module optional. cargo check --no-default-features -p kon-transcription now builds without pulling whisper-rs-sys — the escape hatch brief item #6 / #13 called for on Windows / non-AVX2 / cloud-only builds. load_whisper is cfg-gated behind the same feature. src-tauri/src/commands/models.rs load_model_from_disk returns Box<dyn Transcriber + Send> instead of SpeechBackend; caller chain (ensure_model_loaded, prewarm_default_model) is unchanged. transcriber_trait_is_object_safe test lands alongside the trait as a compile-time witness against future Self-returning / generic-method additions.
This commit is contained in:
@@ -9,7 +9,7 @@ use kon_core::hardware::{self, CpuFeatures};
|
||||
use kon_core::model_registry::{self, Engine, LanguageSupport, ModelEntry};
|
||||
use kon_core::types::{AudioSamples, ModelId, TranscriptionOptions};
|
||||
use kon_transcription::model_manager;
|
||||
use kon_transcription::{load_parakeet, load_whisper, LocalEngine};
|
||||
use kon_transcription::{load_parakeet, load_whisper, LocalEngine, Transcriber};
|
||||
|
||||
/// Map legacy size strings to ModelId.
|
||||
fn whisper_model_id(size: &str) -> ModelId {
|
||||
@@ -73,7 +73,7 @@ fn model_capability(
|
||||
|
||||
pub fn load_model_from_disk(
|
||||
model_id: &ModelId,
|
||||
) -> Result<kon_transcription::SpeechBackend, String> {
|
||||
) -> Result<Box<dyn Transcriber + Send>, String> {
|
||||
let entry =
|
||||
model_registry::find_model(model_id).ok_or_else(|| format!("Unknown model: {model_id}"))?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user