From 48000f47eb0a0ea31cf2569edb86fb421b860fc5 Mon Sep 17 00:00:00 2001 From: hauke Date: Wed, 18 Nov 2026 11:37:24 +0100 Subject: [PATCH] feat #14740: choose the language when starting a transcription Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/core/src/call_view.rs | 4 ++- src-tauri/src/commands.rs | 13 +++++----- src-tauri/src/processing.rs | 22 ++++++++++++----- src-tauri/src/state.rs | 48 +++++++++++++++++++++++++++++++++--- 4 files changed, 71 insertions(+), 16 deletions(-) diff --git a/crates/core/src/call_view.rs b/crates/core/src/call_view.rs index 3bcf321..dbd5b05 100644 --- a/crates/core/src/call_view.rs +++ b/crates/core/src/call_view.rs @@ -188,7 +188,9 @@ pub struct CallDetail { /// The language the picker starts on for `call`: the one it was /// transcribed in, else `last_used` (the settings' `language`). pub fn preselect_language(call: &Call, last_used: &str) -> String { - call.language.clone().unwrap_or_else(|| last_used.to_string()) + call.language + .clone() + .unwrap_or_else(|| last_used.to_string()) } impl CallDetail { diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 23f6228..dcdc501 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -250,16 +250,17 @@ pub async fn discard_call(app: AppHandle, id: CallId) -> CmdResult<()> { } /// Transkribieren in the end-of-call prompt: starts processing in the -/// background and returns at once; the call leaves the prompt. +/// background in the chosen `language` and returns at once; the call +/// leaves the prompt. #[tauri::command] -pub async fn transcribe_call(app: AppHandle, id: CallId) -> CmdResult<()> { - blocking(app, move |app| processing::start(app, id, false)).await +pub async fn transcribe_call(app: AppHandle, id: CallId, language: String) -> CmdResult<()> { + blocking(app, move |app| processing::start(app, id, false, language)).await } -/// Processes a failed (or still undecided) call again. +/// Processes a failed (or still undecided) call again, in `language`. #[tauri::command] -pub async fn retry_call(app: AppHandle, id: CallId) -> CmdResult<()> { - blocking(app, move |app| processing::start(app, id, true)).await +pub async fn retry_call(app: AppHandle, id: CallId, language: String) -> CmdResult<()> { + blocking(app, move |app| processing::start(app, id, true, language)).await } /// After a call left the prompt queue: hides the prompt if no call waits diff --git a/src-tauri/src/processing.rs b/src-tauri/src/processing.rs index 06e54e6..0a8aabb 100644 --- a/src-tauri/src/processing.rs +++ b/src-tauri/src/processing.rs @@ -9,6 +9,7 @@ use std::path::PathBuf; use recorder_core::model::{CallId, CallStatus}; use recorder_core::pipeline::{self, PipelineOptions}; use recorder_core::secrets::Service; +use recorder_core::settings::check_call_language; use recorder_core::transcribe::deepscript::DeepScript; use recorder_core::transcribe::TranscribeError; use serde::Serialize; @@ -57,13 +58,22 @@ impl Drop for Claim { } } -/// Starts processing call `id` in the background and returns at once; the -/// call leaves the end-of-call prompt. `retry` also allows failed calls. -/// Without a DeepScript key nothing starts: the call is marked failed and -/// the error returned. Reads the keyring, so call it off the UI thread. -pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> { +/// Starts processing call `id` in `language` in the background and returns +/// at once; the call leaves the end-of-call prompt. `retry` also allows +/// failed calls. The language is stored with the call and remembered for +/// the next one; one outside `CALL_LANGUAGES` is refused before anything +/// changes. Without a DeepScript key nothing starts: the call is marked +/// failed and the error returned. Reads the keyring, so call it off the UI +/// thread. +pub fn start(app: &AppHandle, id: CallId, retry: bool, language: String) -> Result<(), String> { + check_call_language(&language)?; let claim = Claim::take(app, id, retry)?; let state = app.state::(); + state + .store + .set_language(id, &language) + .map_err(|e| format!("Interner Fehler: {e}"))?; + state.remember_language(&language); let Some(key) = deepscript_key(&state) else { let msg = TranscribeError::MissingKey.user_message(); @@ -76,7 +86,7 @@ pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> { let work_dir = upload_dir(app)?; let settings = state.settings(); let opts = PipelineOptions { - language: settings.language, + language, deepscript_model: settings.deepscript_model, vocabulary: settings.vocabulary, }; diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index 6fad952..73e2958 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -122,16 +122,21 @@ pub struct CallBrief { pub started_at: DateTime, pub ended_at: Option>, pub duration_secs: i64, + /// What the language picker starts on + /// ([`call_view::preselect_language`]). + pub language: String, } impl CallBrief { - fn of(call: &Call) -> Self { + /// `last_used_language` is the settings' `language`. + fn of(call: &Call, last_used_language: &str) -> Self { Self { id: call.id, app: call.app.clone(), started_at: call.started_at, ended_at: call.ended_at, duration_secs: call_view::duration_secs(call), + language: call_view::preselect_language(call, last_used_language), } } } @@ -439,6 +444,15 @@ impl AppState { lock(&self.upload_confirmed_unsaved).insert(id); } + /// Remembers `language` as the last used one, preselected for the next + /// call. Not saving it is only logged: the transcription it was chosen + /// for goes ahead regardless. + pub fn remember_language(&self, language: &str) { + if let Err(e) = self.update_settings(|s| s.language = language.to_string()) { + log::error!("could not remember the call language: {e}"); + } + } + /// Changes and saves settings the app manages itself; saves only if /// something changed. fn update_settings(&self, change: impl FnOnce(&mut Settings)) -> Result<(), String> { @@ -646,7 +660,7 @@ impl AppState { match self.store.get_call(id) { Ok(Some(call)) => { return Some(PendingPrompt { - brief: CallBrief::of(&call), + brief: CallBrief::of(&call, &self.settings().language), more_waiting: queue.len() - 1, }) } @@ -676,7 +690,10 @@ impl AppState { } pub fn call_brief(&self, id: CallId) -> Result { - Ok(CallBrief::of(&self.find_call(id)?)) + Ok(CallBrief::of( + &self.find_call(id)?, + &self.settings().language, + )) } /// All calls for the main window's list, newest first. @@ -1198,11 +1215,36 @@ mod tests { started_at: at(10, 14, 0), ended_at: Some(at(10, 46, 30)), duration_secs: 32 * 60 + 30, + language: "de".into(), } ); assert!(f.state.call_brief(id + 1).is_err()); } + #[test] + fn call_brief_preselects_the_calls_language_else_the_last_used() { + let f = fixture(); + let (id, _, _) = finished_call(&f, "a"); + f.state.remember_language("fr"); + assert_eq!(f.state.call_brief(id).unwrap().language, "fr"); + + f.state.store.set_language(id, "it").unwrap(); + assert_eq!(f.state.call_brief(id).unwrap().language, "it"); + } + + #[test] + fn the_last_used_language_is_remembered_across_restarts() { + let f = fixture(); + + f.state.remember_language("es"); + + assert_eq!(f.state.settings().language, "es"); + assert_eq!( + Settings::load(&f.dir.path().join("settings.json")).language, + "es" + ); + } + fn queued(f: &Fixture) -> Option<(CallId, usize)> { f.state .pending_prompt()