feat #14740: choose the language when starting a transcription
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -188,7 +188,9 @@ pub struct CallDetail {
|
|||||||
/// The language the picker starts on for `call`: the one it was
|
/// The language the picker starts on for `call`: the one it was
|
||||||
/// transcribed in, else `last_used` (the settings' `language`).
|
/// transcribed in, else `last_used` (the settings' `language`).
|
||||||
pub fn preselect_language(call: &Call, last_used: &str) -> String {
|
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 {
|
impl CallDetail {
|
||||||
|
|||||||
@@ -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
|
/// 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]
|
#[tauri::command]
|
||||||
pub async fn transcribe_call(app: AppHandle, id: CallId) -> CmdResult<()> {
|
pub async fn transcribe_call(app: AppHandle, id: CallId, language: String) -> CmdResult<()> {
|
||||||
blocking(app, move |app| processing::start(app, id, false)).await
|
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]
|
#[tauri::command]
|
||||||
pub async fn retry_call(app: AppHandle, id: CallId) -> CmdResult<()> {
|
pub async fn retry_call(app: AppHandle, id: CallId, language: String) -> CmdResult<()> {
|
||||||
blocking(app, move |app| processing::start(app, id, true)).await
|
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
|
/// After a call left the prompt queue: hides the prompt if no call waits
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use std::path::PathBuf;
|
|||||||
use recorder_core::model::{CallId, CallStatus};
|
use recorder_core::model::{CallId, CallStatus};
|
||||||
use recorder_core::pipeline::{self, PipelineOptions};
|
use recorder_core::pipeline::{self, PipelineOptions};
|
||||||
use recorder_core::secrets::Service;
|
use recorder_core::secrets::Service;
|
||||||
|
use recorder_core::settings::check_call_language;
|
||||||
use recorder_core::transcribe::deepscript::DeepScript;
|
use recorder_core::transcribe::deepscript::DeepScript;
|
||||||
use recorder_core::transcribe::TranscribeError;
|
use recorder_core::transcribe::TranscribeError;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -57,13 +58,22 @@ impl Drop for Claim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Starts processing call `id` in the background and returns at once; the
|
/// Starts processing call `id` in `language` in the background and returns
|
||||||
/// call leaves the end-of-call prompt. `retry` also allows failed calls.
|
/// at once; the call leaves the end-of-call prompt. `retry` also allows
|
||||||
/// Without a DeepScript key nothing starts: the call is marked failed and
|
/// failed calls. The language is stored with the call and remembered for
|
||||||
/// the error returned. Reads the keyring, so call it off the UI thread.
|
/// the next one; one outside `CALL_LANGUAGES` is refused before anything
|
||||||
pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> {
|
/// 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 claim = Claim::take(app, id, retry)?;
|
||||||
let state = app.state::<AppState>();
|
let state = app.state::<AppState>();
|
||||||
|
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 Some(key) = deepscript_key(&state) else {
|
||||||
let msg = TranscribeError::MissingKey.user_message();
|
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 work_dir = upload_dir(app)?;
|
||||||
let settings = state.settings();
|
let settings = state.settings();
|
||||||
let opts = PipelineOptions {
|
let opts = PipelineOptions {
|
||||||
language: settings.language,
|
language,
|
||||||
deepscript_model: settings.deepscript_model,
|
deepscript_model: settings.deepscript_model,
|
||||||
vocabulary: settings.vocabulary,
|
vocabulary: settings.vocabulary,
|
||||||
};
|
};
|
||||||
|
|||||||
+45
-3
@@ -122,16 +122,21 @@ pub struct CallBrief {
|
|||||||
pub started_at: DateTime<Local>,
|
pub started_at: DateTime<Local>,
|
||||||
pub ended_at: Option<DateTime<Local>>,
|
pub ended_at: Option<DateTime<Local>>,
|
||||||
pub duration_secs: i64,
|
pub duration_secs: i64,
|
||||||
|
/// What the language picker starts on
|
||||||
|
/// ([`call_view::preselect_language`]).
|
||||||
|
pub language: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallBrief {
|
impl CallBrief {
|
||||||
fn of(call: &Call) -> Self {
|
/// `last_used_language` is the settings' `language`.
|
||||||
|
fn of(call: &Call, last_used_language: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: call.id,
|
id: call.id,
|
||||||
app: call.app.clone(),
|
app: call.app.clone(),
|
||||||
started_at: call.started_at,
|
started_at: call.started_at,
|
||||||
ended_at: call.ended_at,
|
ended_at: call.ended_at,
|
||||||
duration_secs: call_view::duration_secs(call),
|
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);
|
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
|
/// Changes and saves settings the app manages itself; saves only if
|
||||||
/// something changed.
|
/// something changed.
|
||||||
fn update_settings(&self, change: impl FnOnce(&mut Settings)) -> Result<(), String> {
|
fn update_settings(&self, change: impl FnOnce(&mut Settings)) -> Result<(), String> {
|
||||||
@@ -646,7 +660,7 @@ impl AppState {
|
|||||||
match self.store.get_call(id) {
|
match self.store.get_call(id) {
|
||||||
Ok(Some(call)) => {
|
Ok(Some(call)) => {
|
||||||
return Some(PendingPrompt {
|
return Some(PendingPrompt {
|
||||||
brief: CallBrief::of(&call),
|
brief: CallBrief::of(&call, &self.settings().language),
|
||||||
more_waiting: queue.len() - 1,
|
more_waiting: queue.len() - 1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -676,7 +690,10 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn call_brief(&self, id: CallId) -> Result<CallBrief, String> {
|
pub fn call_brief(&self, id: CallId) -> Result<CallBrief, String> {
|
||||||
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.
|
/// All calls for the main window's list, newest first.
|
||||||
@@ -1198,11 +1215,36 @@ mod tests {
|
|||||||
started_at: at(10, 14, 0),
|
started_at: at(10, 14, 0),
|
||||||
ended_at: Some(at(10, 46, 30)),
|
ended_at: Some(at(10, 46, 30)),
|
||||||
duration_secs: 32 * 60 + 30,
|
duration_secs: 32 * 60 + 30,
|
||||||
|
language: "de".into(),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assert!(f.state.call_brief(id + 1).is_err());
|
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)> {
|
fn queued(f: &Fixture) -> Option<(CallId, usize)> {
|
||||||
f.state
|
f.state
|
||||||
.pending_prompt()
|
.pending_prompt()
|
||||||
|
|||||||
Reference in New Issue
Block a user