From 8d757fd639d79610ac94b89175ea91f2d210b2c3 Mon Sep 17 00:00:00 2001 From: hauke Date: Tue, 10 Nov 2026 13:10:50 +0100 Subject: [PATCH] feat #14740: transcription model choice, vocabulary and short-word corrections Co-Authored-By: Claude Sonnet 5 --- crates/core/src/call_view.rs | 69 ++++++++- crates/core/src/corrections.rs | 81 ++++++++++ crates/core/src/lib.rs | 1 + crates/core/src/pipeline.rs | 27 ++++ crates/core/src/settings.rs | 187 ++++++++++++++++++++++- crates/core/src/transcribe/deepscript.rs | 61 ++++++++ crates/core/src/transcribe/mod.rs | 3 + src-tauri/src/processing.rs | 1 + src-tauri/src/state.rs | 9 +- ui/src/lib/api.ts | 2 + ui/src/routes/Settings.svelte | 43 ++++++ 11 files changed, 472 insertions(+), 12 deletions(-) create mode 100644 crates/core/src/corrections.rs diff --git a/crates/core/src/call_view.rs b/crates/core/src/call_view.rs index 45320d1..a709081 100644 --- a/crates/core/src/call_view.rs +++ b/crates/core/src/call_view.rs @@ -6,6 +6,7 @@ use std::collections::BTreeMap; use chrono::{DateTime, Local}; use serde::Serialize; +use crate::corrections::correct_segment_text; use crate::merge; use crate::model::{Call, CallId, CallStatus, Segment, Speaker}; @@ -176,13 +177,18 @@ pub struct CallDetail { impl CallDetail { /// `segments` are the stored ones; `merges` the stored speaker merges /// (source key → target key); `backend_url` is this build's backend - /// (see [`CallListItem::of`]). + /// (see [`CallListItem::of`]); `language` is the call-language setting + /// in effect now (not necessarily what the call was transcribed with), + /// used to apply [`correct_segment_text`] to each segment's text — + /// non-destructively, so it also corrects transcripts from before the + /// correction existed. pub fn of( call: &Call, segments: &[Segment], speaker_names: BTreeMap, merges: &BTreeMap, backend_url: &str, + language: &str, ) -> Self { let segments = merge::apply_merges(segments, merges) .iter() @@ -191,7 +197,7 @@ impl CallDetail { label: merge::label(&segment.speaker, &speaker_names), start: segment.start, end: segment.end, - text: segment.text.clone(), + text: correct_segment_text(&segment.text, language), }) .collect(); Self { @@ -500,6 +506,7 @@ mod tests { names.clone(), &BTreeMap::new(), BACKEND, + "de", ); let lines: Vec<_> = detail @@ -550,6 +557,7 @@ mod tests { names, &merges, BACKEND, + "de", ); let lines: Vec<_> = detail @@ -601,9 +609,15 @@ mod tests { c.transcribed_at = Some(at(10, 20, 0)); let merges = keys(&[("remote:2", "remote:1")]); - let value = - serde_json::to_value(CallDetail::of(&c, &[], BTreeMap::new(), &merges, BACKEND)) - .unwrap(); + let value = serde_json::to_value(CallDetail::of( + &c, + &[], + BTreeMap::new(), + &merges, + BACKEND, + "de", + )) + .unwrap(); assert_eq!( value, @@ -637,12 +651,22 @@ mod tests { } fn detail_with(c: &Call, segments: &[Segment], names: &[(&str, &str)]) -> CallDetail { + detail_with_language(c, segments, names, "de") + } + + fn detail_with_language( + c: &Call, + segments: &[Segment], + names: &[(&str, &str)], + language: &str, + ) -> CallDetail { CallDetail::of( c, segments, keys(names), &keys(&[("remote:2", "remote:1")]), BACKEND, + language, ) } @@ -704,4 +728,39 @@ mod tests { } assert_eq!(NO_TRANSCRIPT, "Kein Transkript zum Hochladen"); } + + #[test] + fn a_whole_segment_mistranscribed_as_english_is_corrected_in_the_detail_view() { + let c = call(Some(at(10, 15, 0))); + let segments = [ + segment(Speaker::Me, 0.0, "Cheers!"), + segment(Speaker::Remote(3), 3.0, "Perfect."), + segment(Speaker::Remote(1), 6.0, "Cheers, see you later."), + ]; + + let detail = detail_with(&c, &segments, &[]); + + let texts: Vec<_> = detail.segments.iter().map(|s| s.text.as_str()).collect(); + assert_eq!(texts, ["Tschüss!", "Perfekt.", "Cheers, see you later."]); + } + + #[test] + fn corrections_are_not_applied_outside_german_calls() { + let c = call(Some(at(10, 15, 0))); + let segments = [segment(Speaker::Me, 0.0, "Cheers!")]; + + let detail = detail_with_language(&c, &segments, &[], "en"); + + assert_eq!(detail.segments[0].text, "Cheers!"); + } + + #[test] + fn the_upload_text_uses_the_corrected_segment_text() { + let c = call(Some(at(10, 46, 0))); + let segments = [segment(Speaker::Me, 0.0, "Cheers!")]; + + let text = detail_with(&c, &segments, &[]).upload_text().unwrap(); + + assert!(text.ends_with("Ich: Tschüss!"), "upload text was: {text}"); + } } diff --git a/crates/core/src/corrections.rs b/crates/core/src/corrections.rs new file mode 100644 index 0000000..19bd079 --- /dev/null +++ b/crates/core/src/corrections.rs @@ -0,0 +1,81 @@ +//! A short, hard-coded list of German short utterances that the +//! transcription service sometimes mistranscribes as English when they +//! stand alone in an otherwise German call ("Tschüss" → "Cheers!", +//! "Perfekt" → "Perfect."). Applied non-destructively wherever a segment's +//! text is shown or uploaded (see [`crate::call_view::CallDetail::of`]), +//! never to the stored segments themselves — fixing the list later fixes +//! already-transcribed calls too. +//! +//! Not user-editable (yet): a fixed code constant, checked only against a +//! segment's *entire* text, so it never touches a short mistranscription +//! embedded in a longer sentence. + +/// (mistranscribed English word, correct German word) pairs. +const CORRECTIONS: &[(&str, &str)] = &[("Cheers", "Tschüss"), ("Perfect", "Perfekt")]; + +/// Returns `text`'s correction if the call's `language` is German (`"de"`) +/// and `text` — ignoring surrounding whitespace and one run of trailing +/// `. ! ? ,` — case-insensitively equals one of [`CORRECTIONS`]'s source +/// words in full; the original trailing punctuation, if any, is kept (e.g. +/// "Cheers!" → "Tschüss!"). Otherwise `text` is returned unchanged, +/// including when it merely *contains* a source word ("Cheers, see you"). +pub fn correct_segment_text(text: &str, language: &str) -> String { + if language != "de" { + return text.to_string(); + } + let trimmed = text.trim(); + let core = trimmed.trim_end_matches(['.', '!', '?', ',']); + let punctuation = &trimmed[core.len()..]; + match CORRECTIONS + .iter() + .find(|(wrong, _)| core.eq_ignore_ascii_case(wrong)) + { + Some((_, right)) => format!("{right}{punctuation}"), + None => text.to_string(), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_whole_mistranscribed_utterance_is_corrected_case_insensitively() { + assert_eq!(correct_segment_text("Cheers!", "de"), "Tschüss!"); + assert_eq!(correct_segment_text("cheers", "de"), "Tschüss"); + assert_eq!(correct_segment_text("CHEERS!", "de"), "Tschüss!"); + assert_eq!(correct_segment_text("Perfect.", "de"), "Perfekt."); + assert_eq!(correct_segment_text("perfect?", "de"), "Perfekt?"); + } + + #[test] + fn surrounding_whitespace_is_ignored_for_matching() { + assert_eq!(correct_segment_text(" Cheers! ", "de"), "Tschüss!"); + } + + #[test] + fn a_mistranscription_inside_a_longer_sentence_is_untouched() { + assert_eq!( + correct_segment_text("Cheers, see you", "de"), + "Cheers, see you" + ); + assert_eq!( + correct_segment_text("That was perfect.", "de"), + "That was perfect." + ); + } + + #[test] + fn not_applied_outside_german_calls() { + assert_eq!(correct_segment_text("Cheers!", "en"), "Cheers!"); + assert_eq!(correct_segment_text("Cheers!", "auto"), "Cheers!"); + } + + #[test] + fn text_without_a_match_is_returned_unchanged() { + assert_eq!( + correct_segment_text("Hallo zusammen.", "de"), + "Hallo zusammen." + ); + } +} diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 1c34549..5a6c64a 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -8,6 +8,7 @@ pub mod audio; pub mod backend; pub mod call_view; pub mod capture; +pub mod corrections; pub mod detect; pub mod http; pub mod merge; diff --git a/crates/core/src/pipeline.rs b/crates/core/src/pipeline.rs index c4828fc..7d5765f 100644 --- a/crates/core/src/pipeline.rs +++ b/crates/core/src/pipeline.rs @@ -25,6 +25,9 @@ pub struct PipelineOptions { /// ISO 639-1 code, or `"auto"`. pub language: String, pub deepscript_model: String, + /// Custom words/names submitted with both tracks (DeepScript's + /// `vocabulary` field). + pub vocabulary: Vec, } /// Everything a pipeline run can fail with. @@ -140,6 +143,7 @@ async fn transcribe( language: opts.language.clone(), model: opts.deepscript_model.clone(), single_speaker, + vocabulary: opts.vocabulary.clone(), }; let (mic_opts, out_opts) = (track_opts(true), track_opts(false)); let (mic_job, out_job) = tokio::join!( @@ -431,6 +435,7 @@ mod tests { PipelineOptions { language: "de".to_string(), deepscript_model: "premium".to_string(), + vocabulary: Vec::new(), } } @@ -547,6 +552,7 @@ mod tests { language: "de".to_string(), model: "premium".to_string(), single_speaker, + vocabulary: Vec::new(), }; assert_eq!( fake.submitted(), @@ -557,6 +563,27 @@ mod tests { ); } + #[tokio::test] + async fn pipeline_forwards_the_vocabulary_to_both_tracks() { + let f = fixture(); + let fake = FakeTranscriber::returning(vec![], vec![]); + let opts = PipelineOptions { + vocabulary: vec!["Tschüss".to_string(), "Euvino".to_string()], + ..opts() + }; + + process_call(&f.store, &fake, f.id, &opts, &f.work_dir()) + .await + .unwrap(); + + for (_, submitted) in fake.submitted() { + assert_eq!( + submitted.vocabulary, + vec!["Tschüss".to_string(), "Euvino".to_string()] + ); + } + } + #[tokio::test] async fn pipeline_transcription_failure_sets_failed_keeps_audio() { let f = fixture(); diff --git a/crates/core/src/settings.rs b/crates/core/src/settings.rs index 76006c6..f29c46f 100644 --- a/crates/core/src/settings.rs +++ b/crates/core/src/settings.rs @@ -27,6 +27,27 @@ pub const START_AFTER_SECS: RangeInclusive = 1..=30; /// splits a call, e.g. when the headset is switched. pub const END_AFTER_SECS: RangeInclusive = 3..=120; +/// The only `deepscript_model` values the settings UI offers (DeepScript's +/// OpenAPI spec also lists `"standard"`, not offered here). An older +/// settings.json with `"standard"` or anything else falls back to the +/// default on load (see [`Settings::load`]) rather than failing. +pub const DEEPSCRIPT_MODELS: [&str; 2] = ["premium", "premium_jade"]; + +/// Default custom-vocabulary terms: short standalone German words/names +/// DeepScript otherwise tends to mistranscribe or drop. +const DEFAULT_VOCABULARY: [&str; 5] = ["Tschüss", "Perfekt", "Servus", "Moin", "Euvino"]; + +/// Hard cap on the vocabulary list sent with every DeepScript submission. +/// DeepScript's OpenAPI spec does not document a limit for the +/// per-transcription `vocabulary` field itself (only for its separate, +/// *saved* vocabularies, capped there at 500 words — see +/// `POST /v1/vocabularies`); these two numbers are ours, chosen to keep +/// that field small. +pub const MAX_VOCABULARY_TERMS: usize = 200; +/// Hard cap on one vocabulary term's length (characters), for the same +/// reason as [`MAX_VOCABULARY_TERMS`]. +pub const MAX_VOCABULARY_TERM_LEN: usize = 60; + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(default)] pub struct Settings { @@ -35,6 +56,12 @@ pub struct Settings { pub output_device: Option, pub language: String, pub deepscript_model: String, + /// Custom words/names submitted with every transcription (DeepScript's + /// `vocabulary` field), e.g. names and product terms that are often + /// misheard. Normalized on load and on every edit (see + /// [`normalize_vocabulary`]): trimmed, blanks dropped, deduplicated + /// case-insensitively, order kept. + pub vocabulary: Vec, pub retention_days: u32, pub autostart: bool, pub start_after_secs: u64, @@ -57,6 +84,7 @@ impl Default for Settings { output_device: None, language: "de".to_string(), deepscript_model: "premium".to_string(), + vocabulary: DEFAULT_VOCABULARY.iter().map(|s| s.to_string()).collect(), retention_days: 7, autostart: true, start_after_secs: 3, @@ -85,13 +113,35 @@ impl Settings { END_AFTER_SECS.end() )); } + if !DEEPSCRIPT_MODELS.contains(&self.deepscript_model.as_str()) { + return Err(format!( + "Transkriptionsmodell: nur {} möglich", + DEEPSCRIPT_MODELS.join(" oder ") + )); + } + if self.vocabulary.len() > MAX_VOCABULARY_TERMS { + return Err(format!( + "Vokabular: höchstens {MAX_VOCABULARY_TERMS} Begriffe" + )); + } + if let Some(term) = self + .vocabulary + .iter() + .find(|term| term.chars().count() > MAX_VOCABULARY_TERM_LEN) + { + return Err(format!( + "Vokabular: „{term}“ ist länger als {MAX_VOCABULARY_TERM_LEN} Zeichen" + )); + } Ok(()) } - /// The settings after the user saved `edited` over these: checked, with - /// the backend login (which only the app changes) kept, so a settings - /// page loaded before a login cannot undo it. + /// The settings after the user saved `edited` over these: normalized + /// (see [`normalize_vocabulary`]), checked, with the backend login + /// (which only the app changes) kept, so a settings page loaded before + /// a login cannot undo it. pub fn edited(&self, mut edited: Settings) -> Result { + edited.vocabulary = normalize_vocabulary(edited.vocabulary); edited.validate()?; edited.backend_username = self.backend_username.clone(); edited.backend_key_expires_at = self.backend_key_expires_at; @@ -100,12 +150,20 @@ impl Settings { } /// Reads the settings file. A missing or unreadable file yields the - /// defaults; fields missing from the file take their default value. + /// defaults; fields missing from the file take their default value. A + /// `deepscript_model` outside [`DEEPSCRIPT_MODELS`] (e.g. an older + /// file's `"standard"`) falls back to the default instead of failing; + /// `vocabulary` is normalized (see [`normalize_vocabulary`]). pub fn load(path: &Path) -> Settings { - fs::read_to_string(path) + let mut settings: Settings = fs::read_to_string(path) .ok() .and_then(|json| serde_json::from_str(&json).ok()) - .unwrap_or_default() + .unwrap_or_default(); + if !DEEPSCRIPT_MODELS.contains(&settings.deepscript_model.as_str()) { + settings.deepscript_model = Settings::default().deepscript_model; + } + settings.vocabulary = normalize_vocabulary(settings.vocabulary); + settings } /// Writes the settings file (creating its directory), replacing the old @@ -121,6 +179,23 @@ impl Settings { } } +/// Trims each term, drops blanks, and deduplicates case-insensitively while +/// keeping the first occurrence's spelling and order. +fn normalize_vocabulary(terms: Vec) -> Vec { + let mut seen = std::collections::HashSet::new(); + terms + .into_iter() + .filter_map(|term| { + let trimmed = term.trim(); + if trimmed.is_empty() { + return None; + } + seen.insert(trimmed.to_lowercase()) + .then(|| trimmed.to_string()) + }) + .collect() +} + #[cfg(test)] mod tests { use super::*; @@ -143,6 +218,10 @@ mod tests { assert_eq!(s.output_device, None); assert_eq!(s.language, "de"); assert_eq!(s.deepscript_model, "premium"); + assert_eq!( + s.vocabulary, + vec!["Tschüss", "Perfekt", "Servus", "Moin", "Euvino"] + ); assert_eq!(s.retention_days, 7); assert!(s.autostart); assert_eq!(s.start_after_secs, 3); @@ -170,6 +249,32 @@ mod tests { ); } + #[test] + fn an_older_files_model_and_a_missing_vocabulary_fall_back_to_the_default() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("settings.json"); + fs::write(&path, r#"{"deepscript_model": "standard"}"#).unwrap(); + assert_eq!(Settings::load(&path), Settings::default()); + + fs::write(&path, r#"{"deepscript_model": "nonsense"}"#).unwrap(); + assert_eq!(Settings::load(&path), Settings::default()); + } + + #[test] + fn loading_normalizes_the_stored_vocabulary() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("settings.json"); + fs::write( + &path, + r#"{"vocabulary": [" Tschüss ", "", "TSCHÜSS", " ", "Euvino"]}"#, + ) + .unwrap(); + assert_eq!( + Settings::load(&path).vocabulary, + vec!["Tschüss".to_string(), "Euvino".to_string()] + ); + } + fn logged_in() -> Settings { Settings { backend_username: Some("hinrichs".into()), @@ -249,6 +354,76 @@ mod tests { } } + #[test] + fn validate_rejects_a_model_outside_the_offered_two() { + for model in ["standard", "nonsense", ""] { + let s = Settings { + deepscript_model: model.to_string(), + ..Settings::default() + }; + assert_eq!( + s.validate(), + Err("Transkriptionsmodell: nur premium oder premium_jade möglich".to_string()) + ); + } + for model in ["premium", "premium_jade"] { + let s = Settings { + deepscript_model: model.to_string(), + ..Settings::default() + }; + assert_eq!(s.validate(), Ok(())); + } + } + + #[test] + fn validate_rejects_too_many_vocabulary_terms() { + let s = Settings { + vocabulary: (0..=MAX_VOCABULARY_TERMS).map(|n| n.to_string()).collect(), + ..Settings::default() + }; + assert_eq!( + s.validate(), + Err(format!( + "Vokabular: höchstens {MAX_VOCABULARY_TERMS} Begriffe" + )) + ); + } + + #[test] + fn validate_rejects_a_too_long_vocabulary_term() { + let s = Settings { + vocabulary: vec!["a".repeat(MAX_VOCABULARY_TERM_LEN + 1)], + ..Settings::default() + }; + assert_eq!( + s.validate(), + Err(format!( + "Vokabular: „{}“ ist länger als {MAX_VOCABULARY_TERM_LEN} Zeichen", + "a".repeat(MAX_VOCABULARY_TERM_LEN + 1) + )) + ); + } + + #[test] + fn an_edit_normalizes_the_vocabulary_before_validating_and_saving() { + let edited = Settings { + vocabulary: vec![ + " Tschüss ".to_string(), + "".to_string(), + "TSCHÜSS".to_string(), + "Kisling".to_string(), + ], + ..Settings::default() + }; + + let saved = logged_in().edited(edited).unwrap(); + + assert_eq!( + saved.vocabulary, + vec!["Tschüss".to_string(), "Kisling".to_string()] + ); + } + #[test] fn settings_load_missing_file_returns_default() { let dir = tempfile::tempdir().unwrap(); diff --git a/crates/core/src/transcribe/deepscript.rs b/crates/core/src/transcribe/deepscript.rs index 7e8d296..f6d867e 100644 --- a/crates/core/src/transcribe/deepscript.rs +++ b/crates/core/src/transcribe/deepscript.rs @@ -201,6 +201,15 @@ impl Transcriber for DeepScript { value: "1".to_string(), }); } + if !opts.vocabulary.is_empty() { + parts.push(Part::Text { + name: "vocabulary".to_string(), + // The documented format: "JSON array of custom words, or + // comma-separated string." + value: serde_json::to_string(&opts.vocabulary) + .expect("Vec always serializes"), + }); + } let req = HttpRequest { method: Method::Post, @@ -385,6 +394,7 @@ mod tests { language: language.to_string(), model: model.to_string(), single_speaker, + vocabulary: Vec::new(), } } @@ -439,6 +449,57 @@ mod tests { transport.assert_done(); } + #[tokio::test] + async fn submit_sends_vocabulary_as_a_json_array_string() { + let transport = Arc::new(FakeTransport::new()); + transport.expect( + Method::Post, + &format!("{BASE}/transcriptions"), + 202, + r#"{"data":{"id":"job-voc","status":"queued","model":"premium","originalFileName":"mic.flac","createdOn":"2026-01-01T00:00:00Z"}}"#, + ); + let ds = deep_script(&transport); + let mut vocab_opts = opts("premium", "de", true); + vocab_opts.vocabulary = vec!["Tschüss".to_string(), "Euvino".to_string()]; + + ds.submit(Path::new("mic.flac"), &vocab_opts).await.unwrap(); + + let requests = transport.requests(); + let HttpBody::Multipart(parts) = &requests[0].body else { + panic!("expected multipart body"); + }; + assert!(parts.contains(&Part::Text { + name: "vocabulary".to_string(), + value: r#"["Tschüss","Euvino"]"#.to_string(), + })); + transport.assert_done(); + } + + #[tokio::test] + async fn submit_omits_vocabulary_when_empty() { + let transport = Arc::new(FakeTransport::new()); + transport.expect( + Method::Post, + &format!("{BASE}/transcriptions"), + 202, + r#"{"data":{"id":"job-novoc","status":"queued","model":"premium","originalFileName":"mic.flac","createdOn":"2026-01-01T00:00:00Z"}}"#, + ); + let ds = deep_script(&transport); + + ds.submit(Path::new("mic.flac"), &opts("premium", "de", true)) + .await + .unwrap(); + + let requests = transport.requests(); + let HttpBody::Multipart(parts) = &requests[0].body else { + panic!("expected multipart body"); + }; + assert!(!parts + .iter() + .any(|p| matches!(p, Part::Text { name, .. } if name == "vocabulary"))); + transport.assert_done(); + } + #[tokio::test] async fn submit_without_hint_for_output_track() { let transport = Arc::new(FakeTransport::new()); diff --git a/crates/core/src/transcribe/mod.rs b/crates/core/src/transcribe/mod.rs index 9967d3d..0696ee1 100644 --- a/crates/core/src/transcribe/mod.rs +++ b/crates/core/src/transcribe/mod.rs @@ -24,6 +24,9 @@ pub struct TranscribeOptions { /// the user) — the output track may have several, so this is left /// unset there. pub single_speaker: bool, + /// Custom words/names to bias the transcription towards (DeepScript's + /// `vocabulary` field); empty omits the field entirely. + pub vocabulary: Vec, } /// Uploads an audio file to a remote speech-to-text service, waits for the diff --git a/src-tauri/src/processing.rs b/src-tauri/src/processing.rs index 4c8a079..06e54e6 100644 --- a/src-tauri/src/processing.rs +++ b/src-tauri/src/processing.rs @@ -78,6 +78,7 @@ pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> { let opts = PipelineOptions { language: settings.language, deepscript_model: settings.deepscript_model, + vocabulary: settings.vocabulary, }; // A fresh client per run, so a key changed in the settings applies to // the next run. diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index 288f45b..cdc6630 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -647,7 +647,14 @@ impl AppState { let segments = self.store.segments(id).map_err(|e| e.to_string())?; let names = self.store.speaker_names(id).map_err(|e| e.to_string())?; let merges = self.store.speaker_merges(id).map_err(|e| e.to_string())?; - let mut detail = CallDetail::of(&call, &segments, names, &merges, &self.backend_url); + let mut detail = CallDetail::of( + &call, + &segments, + names, + &merges, + &self.backend_url, + &self.settings().language, + ); detail.uploading = self.is_uploading(id); Ok(detail) } diff --git a/ui/src/lib/api.ts b/ui/src/lib/api.ts index 4377120..f22774f 100644 --- a/ui/src/lib/api.ts +++ b/ui/src/lib/api.ts @@ -11,6 +11,8 @@ export interface Settings { output_device: string | null language: string deepscript_model: string + /** Custom words/names submitted with every transcription. */ + vocabulary: string[] retention_days: number autostart: boolean start_after_secs: number diff --git a/ui/src/routes/Settings.svelte b/ui/src/routes/Settings.svelte index 54ef445..c910437 100644 --- a/ui/src/routes/Settings.svelte +++ b/ui/src/routes/Settings.svelte @@ -43,6 +43,10 @@ ] let settings = $state(null) + /** The vocabulary textarea's raw text, one term per line; converted + * to/from `settings.vocabulary` on load/save (the backend trims, drops + * blanks and deduplicates — see `Settings::edited`). */ + let vocabularyText = $state('') let devices = $state({ inputs: [], outputs: [] }) let keySaved = $state>({ deepscript: false }) let keyInput = $state>({ deepscript: '' }) @@ -207,6 +211,7 @@ async function load() { try { settings = await getSettings() + vocabularyText = settings.vocabulary.join('\n') for (const { id } of services) keySaved[id] = await hasApiKey(id) devices = await listDevices() } catch (err) { @@ -268,7 +273,12 @@ if (!Number.isInteger(settings.retention_days) || settings.retention_days < 1) { throw 'Aufbewahrung: bitte eine ganze Zahl ab 1 eingeben' } + settings.vocabulary = vocabularyText.split('\n') await saveSettings($state.snapshot(settings)) + // Re-read: the backend trims/dedupes the vocabulary, so the textarea + // should show the cleaned-up list, not what was just typed. + settings = await getSettings() + vocabularyText = settings.vocabulary.join('\n') } async function runTest() { @@ -474,6 +484,24 @@ +
+

Transkription

+
+ + + + Gilt für neue Transkriptionen. +
+ + +

+ Namen, Firmen- und Produktbegriffe, die oft falsch erkannt werden. +

+
+

Updates

@@ -575,6 +603,21 @@ justify-self: start; } + .vocabulary-label { + display: block; + margin-top: 12px; + font-weight: 600; + } + + textarea#vocabulary { + width: 100%; + max-width: 420px; + margin-top: 6px; + font-family: inherit; + font-size: 13px; + resize: vertical; + } + .hint { margin: 12px 0; padding: 8px 10px;