feat: OpenWhispr-inspired transcription polish pass
Some checks failed
check / cargo check (macos-latest) (push) Has been cancelled
check / cargo check (ubuntu-22.04) (push) Has been cancelled
check / cargo check (windows-latest) (push) Has been cancelled
check / svelte build + lint (push) Has been cancelled

Major quality pass on top of Phase 2. Five substantive changes plus
cross-cutting touches across audio, hotkey, transcription, and Tauri
command layers.

  Transcription quality

  - Long-audio chunking in commands/transcription.rs: Parakeet and large
    file transcription now chunk-and-recompose with overlap trimming, so
    the live-path chunking advantage extends to file-based workflows.
  - Stateful live speech gate in commands/live.rs on top of the earlier
    duplicate-boundary filtering — distinguishes start-of-speech from
    mid-speech and holds state across chunks.

  Auto-learning corrections

  - New crates/ai-formatting/src/correction_learning.rs: extracts user
    text corrections from viewer edits and proposes additions to the
    active profile's vocabulary.
  - src-tauri/src/commands/profiles.rs bridge for frontend-driven
    confirmation of learned terms.
  - src/routes/viewer/+page.svelte hooks the learning path into the
    segment-edit flow so corrections feed profile_terms without a
    separate 'train this profile' UX.

  Transcript profile provenance

  - Migration v8 (crates/storage/src/migrations.rs) adds profile_id to
    transcripts, defaulting to DEFAULT_PROFILE_ID so existing rows stay
    valid.
  - crates/storage/src/database.rs: TranscriptRow + CRUD carry profile_id.
  - src-tauri/src/commands/transcripts.rs: add_transcript accepts and
    persists profile_id.
  - DictationPage.svelte + FilesPage.svelte send activeProfileId on
    capture so learned corrections are attributed to the right profile.

  Cleanup prompt contract

  - crates/ai-formatting/src/llm_client.rs hardened: the CLEANUP_PROMPT
    now specifies concrete do/do-not rules, ready for a real model-backed
    cleanup pass. The llm_client is still a stub — kon-llm remains unwired
    — but the prompt shape is final.

  Cross-cutting polish

  - Minor touches in audio (capture/decode/resample), hotkey (lib/linux/stub),
    core, transcription (concurrency/model_manager/local_engine/whisper_rs),
    and the rest of src-tauri/src/commands/*: error-path tightening, log
    clarity, TS-migration follow-ups (@ts-nocheck additions for incremental
    typing).

Verified locally: npm run check, cargo test -p kon-ai-formatting,
cargo test -p kon-storage, cargo test -p kon --lib commands::live::tests,
cargo check — all green.

Scope boundary: kon-llm crate is still a stub; task extraction remains
rule-based. Bundled local-LLM runtime is the next clean step and is not
in this commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-19 22:39:08 +01:00
parent 28acdcfa6d
commit 34fce3cf9e
39 changed files with 1581 additions and 554 deletions

View File

@@ -12,11 +12,7 @@ pub async fn run_inference(
audio: AudioSamples,
options: TranscriptionOptions,
) -> Result<TimedTranscript> {
tokio::task::spawn_blocking(move || {
engine.transcribe_sync(&audio, &options)
})
.await
.map_err(|e| {
KonError::TranscriptionFailed(format!("Task join error: {e}"))
})?
tokio::task::spawn_blocking(move || engine.transcribe_sync(&audio, &options))
.await
.map_err(|e| KonError::TranscriptionFailed(format!("Task join error: {e}")))?
}

View File

@@ -4,10 +4,6 @@ pub mod model_manager;
pub mod whisper_rs_backend;
pub use concurrency::run_inference;
pub use local_engine::{
load_parakeet, load_whisper, LocalEngine, SpeechBackend, TimedTranscript,
};
pub use local_engine::{load_parakeet, load_whisper, LocalEngine, SpeechBackend, TimedTranscript};
pub use model_manager::{download, is_downloaded, list_downloaded, model_dir, models_dir};
pub use transcribe_rs::SpeechModel;
pub use model_manager::{
download, is_downloaded, list_downloaded, model_dir, models_dir,
};

View File

@@ -6,8 +6,7 @@ use transcribe_rs::{SpeechModel, TranscribeOptions, TranscriptionResult};
use kon_core::error::{KonError, Result};
use kon_core::types::{
AudioSamples, EngineName, ModelId, Segment, Transcript,
TranscriptionOptions,
AudioSamples, EngineName, ModelId, Segment, Transcript, TranscriptionOptions,
};
use crate::whisper_rs_backend::WhisperRsBackend;
@@ -48,8 +47,7 @@ impl LocalEngine {
}
pub fn load(&self, backend: SpeechBackend, model_id: ModelId) {
let mut guard =
self.engine.lock().unwrap_or_else(|e| e.into_inner());
let mut guard = self.engine.lock().unwrap_or_else(|e| e.into_inner());
*guard = Some(backend);
let mut id_guard = self
.loaded_model_id
@@ -71,8 +69,7 @@ impl LocalEngine {
}
pub fn is_loaded(&self) -> bool {
let guard =
self.engine.lock().unwrap_or_else(|e| e.into_inner());
let guard = self.engine.lock().unwrap_or_else(|e| e.into_inner());
guard.is_some()
}
@@ -83,8 +80,7 @@ impl LocalEngine {
audio: &AudioSamples,
options: &TranscriptionOptions,
) -> Result<TimedTranscript> {
let mut guard =
self.engine.lock().unwrap_or_else(|e| e.into_inner());
let mut guard = self.engine.lock().unwrap_or_else(|e| e.into_inner());
let backend = guard.as_mut().ok_or(KonError::EngineNotLoaded)?;
let start = Instant::now();
@@ -119,10 +115,7 @@ impl LocalEngine {
Ok(TimedTranscript {
transcript: Transcript::new(
segments,
options
.language
.clone()
.unwrap_or_else(|| "en".to_string()),
options.language.clone().unwrap_or_else(|| "en".to_string()),
audio.duration_secs(),
),
inference_ms,
@@ -169,23 +162,17 @@ impl transcribe_rs::SpeechModel for ParakeetWordGranularity {
/// Load a Parakeet model from a directory path.
pub fn load_parakeet(model_dir: &Path) -> Result<SpeechBackend> {
use transcribe_rs::onnx::Quantization;
let model = transcribe_rs::onnx::parakeet::ParakeetModel::load(
model_dir,
&Quantization::Int8,
)
.map_err(|e| {
KonError::TranscriptionFailed(format!(
"Failed to load Parakeet: {e}"
))
})?;
Ok(SpeechBackend::Adapter(Box::new(ParakeetWordGranularity(model))))
let model = transcribe_rs::onnx::parakeet::ParakeetModel::load(model_dir, &Quantization::Int8)
.map_err(|e| KonError::TranscriptionFailed(format!("Failed to load Parakeet: {e}")))?;
Ok(SpeechBackend::Adapter(Box::new(ParakeetWordGranularity(
model,
))))
}
/// Load a Whisper model from a GGML file path via whisper-rs.
pub fn load_whisper(model_path: &Path) -> Result<SpeechBackend> {
let backend = WhisperRsBackend::load(model_path).map_err(|e| {
KonError::TranscriptionFailed(format!("Failed to load Whisper: {e}"))
})?;
let backend = WhisperRsBackend::load(model_path)
.map_err(|e| KonError::TranscriptionFailed(format!("Failed to load Whisper: {e}")))?;
Ok(SpeechBackend::WhisperRs(backend))
}

View File

@@ -9,8 +9,7 @@ use kon_core::types::{DownloadProgress, ModelId};
/// Unix: ~/.kon/models
pub fn models_dir() -> PathBuf {
if cfg!(target_os = "windows") {
let local_app_data = std::env::var("LOCALAPPDATA")
.unwrap_or_else(|_| ".".to_string());
let local_app_data = std::env::var("LOCALAPPDATA").unwrap_or_else(|_| ".".to_string());
PathBuf::from(local_app_data).join("kon").join("models")
} else {
dirs_path().join("models")
@@ -19,12 +18,10 @@ pub fn models_dir() -> PathBuf {
fn dirs_path() -> PathBuf {
if cfg!(target_os = "windows") {
let local_app_data = std::env::var("LOCALAPPDATA")
.unwrap_or_else(|_| ".".to_string());
let local_app_data = std::env::var("LOCALAPPDATA").unwrap_or_else(|_| ".".to_string());
PathBuf::from(local_app_data).join("kon")
} else {
let home =
std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string());
let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string());
PathBuf::from(home).join(".kon")
}
}
@@ -59,8 +56,7 @@ pub async fn download(
id: &ModelId,
progress: impl Fn(DownloadProgress) + Send + 'static,
) -> Result<()> {
let entry = find_model(id)
.ok_or_else(|| KonError::ModelNotFound(id.clone()))?;
let entry = find_model(id).ok_or_else(|| KonError::ModelNotFound(id.clone()))?;
let dir = model_dir(id);
std::fs::create_dir_all(&dir)?;
@@ -103,9 +99,7 @@ async fn download_file(
// Check for existing partial download (resume support)
let existing_bytes = if part_path.exists() {
std::fs::metadata(&part_path)
.map(|m| m.len())
.unwrap_or(0)
std::fs::metadata(&part_path).map(|m| m.len()).unwrap_or(0)
} else {
0
};
@@ -146,9 +140,7 @@ async fn download_file(
// Open file for append (resume) or create (fresh start)
let mut out = if actually_resuming {
std::fs::OpenOptions::new()
.append(true)
.open(&part_path)?
std::fs::OpenOptions::new().append(true).open(&part_path)?
} else {
std::fs::File::create(&part_path)?
};
@@ -161,8 +153,7 @@ async fn download_file(
// restart from scratch in that case.
while let Some(chunk) = stream.next().await {
let chunk = chunk
.map_err(|e| KonError::DownloadFailed(e.to_string()))?;
let chunk = chunk.map_err(|e| KonError::DownloadFailed(e.to_string()))?;
std::io::Write::write_all(&mut out, &chunk)?;
if let Some(ref mut h) = hasher {
h.update(&chunk);

View File

@@ -28,11 +28,8 @@ pub struct WhisperRsBackend {
impl WhisperRsBackend {
pub fn load(model_path: &Path) -> Result<Self, WhisperBackendError> {
let ctx = WhisperContext::new_with_params(
model_path,
WhisperContextParameters::default(),
)
.map_err(|e| WhisperBackendError::Load(e.to_string()))?;
let ctx = WhisperContext::new_with_params(model_path, WhisperContextParameters::default())
.map_err(|e| WhisperBackendError::Load(e.to_string()))?;
Ok(Self { ctx })
}