58 lines
2.1 KiB
Rust
58 lines
2.1 KiB
Rust
//! Transcription engine (Phase 1 CPU; Phase 3 acceleration). FR-TRX-*.
|
|
//!
|
|
//! Primary engine: whisper-rs (whisper.cpp) for CPU/Vulkan/CUDA. The NPU path is
|
|
//! a second `Transcriber` impl using ONNX Runtime (ort + DirectML) — same trait,
|
|
//! same `TranscriptSegment` output (ADR-0003/0004). Callers never branch on engine.
|
|
|
|
use crate::models::{BackendId, TranscriptSegment};
|
|
use std::path::Path;
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum TrxError {
|
|
#[error("model load failed: {0}")]
|
|
Load(String),
|
|
#[error("inference failed: {0}")]
|
|
Inference(String),
|
|
}
|
|
|
|
/// A chunk of audio (mono f32, 16 kHz) handed to the streaming transcriber.
|
|
pub struct AudioWindow {
|
|
pub samples: Vec<f32>,
|
|
pub offset_ms: u64,
|
|
}
|
|
|
|
/// Where produced segments are delivered (interim then final).
|
|
pub type SegmentSink = std::sync::mpsc::Sender<TranscriptSegment>;
|
|
|
|
pub trait Transcriber: Send + Sync {
|
|
fn load(model: &Path, backend: BackendId) -> Result<Self, TrxError>
|
|
where
|
|
Self: Sized;
|
|
/// Streaming: emit interim + final segments for a window (FR-TRX-2).
|
|
fn transcribe_stream(&self, audio: AudioWindow, out: SegmentSink) -> Result<(), TrxError>;
|
|
/// Batch: one-shot, higher accuracy (FR-TRX-3).
|
|
fn transcribe_file(&self, wav: &Path) -> Result<Vec<TranscriptSegment>, TrxError>;
|
|
}
|
|
|
|
/// whisper.cpp-backed transcriber (CPU baseline; GPU via Cargo features).
|
|
#[cfg(feature = "cpu-transcription")]
|
|
pub struct WhisperTranscriber;
|
|
|
|
#[cfg(feature = "cpu-transcription")]
|
|
impl Transcriber for WhisperTranscriber {
|
|
fn load(_model: &Path, _backend: BackendId) -> Result<Self, TrxError> {
|
|
// T1.5 / T3.3: init whisper-rs with the backend's acceleration features.
|
|
todo!("Phase 1 — load whisper model")
|
|
}
|
|
fn transcribe_stream(&self, _audio: AudioWindow, _out: SegmentSink) -> Result<(), TrxError> {
|
|
todo!("Phase 1 — streaming transcription")
|
|
}
|
|
fn transcribe_file(&self, _wav: &Path) -> Result<Vec<TranscriptSegment>, TrxError> {
|
|
todo!("Phase 3 — batch transcription")
|
|
}
|
|
}
|
|
|
|
/// ONNX Runtime + DirectML transcriber for the NPU tier (Phase 3).
|
|
#[cfg(feature = "directml")]
|
|
pub struct OnnxNpuTranscriber;
|