feat #14740: allowed call languages and per-call corrections
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -179,14 +179,24 @@ pub struct CallDetail {
|
|||||||
/// Whether retention deleted the call's audio (as opposed to the files
|
/// Whether retention deleted the call's audio (as opposed to the files
|
||||||
/// being missing for another reason).
|
/// being missing for another reason).
|
||||||
pub audio_deleted: bool,
|
pub audio_deleted: bool,
|
||||||
|
/// The call's language, or the last-used one for a call without its
|
||||||
|
/// own yet ([`preselect_language`]): what the language picker next to
|
||||||
|
/// "Transkribieren"/"Erneut versuchen" starts on.
|
||||||
|
pub language: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallDetail {
|
impl CallDetail {
|
||||||
/// `segments` are the stored ones; `merges` the stored speaker merges
|
/// `segments` are the stored ones; `merges` the stored speaker merges
|
||||||
/// (source key → target key); `backend_url` is this build's backend
|
/// (source key → target key); `backend_url` is this build's backend
|
||||||
/// (see [`CallListItem::of`]); `language` is the call-language setting
|
/// (see [`CallListItem::of`]); `last_used_language` is the settings'
|
||||||
/// in effect now (not necessarily what the call was transcribed with),
|
/// `language` (see [`preselect_language`]). The call's language picks
|
||||||
/// used to apply [`correct_segment_text`] to each segment's text —
|
/// the [`correct_segment_text`] applied to each segment's text —
|
||||||
/// non-destructively, so it also corrects transcripts from before the
|
/// non-destructively, so it also corrects transcripts from before the
|
||||||
/// correction existed.
|
/// correction existed.
|
||||||
pub fn of(
|
pub fn of(
|
||||||
@@ -195,8 +205,11 @@ impl CallDetail {
|
|||||||
speaker_names: BTreeMap<String, String>,
|
speaker_names: BTreeMap<String, String>,
|
||||||
merges: &BTreeMap<String, String>,
|
merges: &BTreeMap<String, String>,
|
||||||
backend_url: &str,
|
backend_url: &str,
|
||||||
language: &str,
|
last_used_language: &str,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
// A call with segments always has its language (see the store's
|
||||||
|
// schema v5); the fallback only covers a call not transcribed yet.
|
||||||
|
let language = preselect_language(call, last_used_language);
|
||||||
let segments = merge::apply_merges(segments, merges)
|
let segments = merge::apply_merges(segments, merges)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|segment| SegmentView {
|
.map(|segment| SegmentView {
|
||||||
@@ -204,7 +217,7 @@ impl CallDetail {
|
|||||||
label: merge::label(&segment.speaker, &speaker_names),
|
label: merge::label(&segment.speaker, &speaker_names),
|
||||||
start: segment.start,
|
start: segment.start,
|
||||||
end: segment.end,
|
end: segment.end,
|
||||||
text: correct_segment_text(&segment.text, language),
|
text: correct_segment_text(&segment.text, &language),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Self {
|
Self {
|
||||||
@@ -219,6 +232,7 @@ impl CallDetail {
|
|||||||
audio_available: false,
|
audio_available: false,
|
||||||
audio_deleted: call.audio_deleted,
|
audio_deleted: call.audio_deleted,
|
||||||
speaker_names,
|
speaker_names,
|
||||||
|
language,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -658,19 +672,22 @@ mod tests {
|
|||||||
"uploading": false,
|
"uploading": false,
|
||||||
"audio_available": false,
|
"audio_available": false,
|
||||||
"audio_deleted": false,
|
"audio_deleted": false,
|
||||||
|
"language": "de",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// With German as the last-used language (what matters for a call
|
||||||
|
/// without its own, see `CallDetail::of`).
|
||||||
fn detail_with(c: &Call, segments: &[Segment], names: &[(&str, &str)]) -> CallDetail {
|
fn detail_with(c: &Call, segments: &[Segment], names: &[(&str, &str)]) -> CallDetail {
|
||||||
detail_with_language(c, segments, names, "de")
|
detail_last_used(c, segments, names, "de")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detail_with_language(
|
fn detail_last_used(
|
||||||
c: &Call,
|
c: &Call,
|
||||||
segments: &[Segment],
|
segments: &[Segment],
|
||||||
names: &[(&str, &str)],
|
names: &[(&str, &str)],
|
||||||
language: &str,
|
last_used_language: &str,
|
||||||
) -> CallDetail {
|
) -> CallDetail {
|
||||||
CallDetail::of(
|
CallDetail::of(
|
||||||
c,
|
c,
|
||||||
@@ -678,7 +695,7 @@ mod tests {
|
|||||||
keys(names),
|
keys(names),
|
||||||
&keys(&[("remote:2", "remote:1")]),
|
&keys(&[("remote:2", "remote:1")]),
|
||||||
BACKEND,
|
BACKEND,
|
||||||
language,
|
last_used_language,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -758,14 +775,38 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn corrections_are_not_applied_outside_german_calls() {
|
fn corrections_are_not_applied_outside_german_calls() {
|
||||||
let c = call(Some(at(10, 15, 0)));
|
let mut c = call(Some(at(10, 15, 0)));
|
||||||
|
c.language = Some("en".into());
|
||||||
let segments = [segment(Speaker::Me, 0.0, "Cheers!")];
|
let segments = [segment(Speaker::Me, 0.0, "Cheers!")];
|
||||||
|
|
||||||
let detail = detail_with_language(&c, &segments, &[], "en");
|
// German was used last, but this call is English.
|
||||||
|
let detail = detail_last_used(&c, &segments, &[], "de");
|
||||||
|
|
||||||
assert_eq!(detail.segments[0].text, "Cheers!");
|
assert_eq!(detail.segments[0].text, "Cheers!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn corrections_follow_the_calls_language_not_the_last_used_one() {
|
||||||
|
let mut c = call(Some(at(10, 15, 0)));
|
||||||
|
c.language = Some("de".into());
|
||||||
|
let segments = [segment(Speaker::Me, 0.0, "Cheers!")];
|
||||||
|
|
||||||
|
let detail = detail_last_used(&c, &segments, &[], "en");
|
||||||
|
|
||||||
|
assert_eq!(detail.segments[0].text, "Tschüss!");
|
||||||
|
assert_eq!(detail.language, "de");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_preselected_language_is_the_calls_own_else_the_last_used() {
|
||||||
|
let mut c = call(None);
|
||||||
|
assert_eq!(preselect_language(&c, "fr"), "fr");
|
||||||
|
|
||||||
|
c.language = Some("it".into());
|
||||||
|
assert_eq!(preselect_language(&c, "fr"), "it");
|
||||||
|
assert_eq!(detail_last_used(&c, &[], &[], "fr").language, "it");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn the_upload_text_uses_the_corrected_segment_text() {
|
fn the_upload_text_uses_the_corrected_segment_text() {
|
||||||
let c = call(Some(at(10, 46, 0)));
|
let c = call(Some(at(10, 46, 0)));
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use crate::transcribe::{TranscribeError, TranscribeOptions, Transcriber};
|
|||||||
/// Settings a pipeline run uses.
|
/// Settings a pipeline run uses.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct PipelineOptions {
|
pub struct PipelineOptions {
|
||||||
/// ISO 639-1 code, or `"auto"`.
|
/// The call's language, one of [`crate::settings::CALL_LANGUAGES`].
|
||||||
pub language: String,
|
pub language: String,
|
||||||
pub deepscript_model: String,
|
pub deepscript_model: String,
|
||||||
/// Custom words/names submitted with both tracks (DeepScript's
|
/// Custom words/names submitted with both tracks (DeepScript's
|
||||||
|
|||||||
@@ -35,6 +35,20 @@ pub const RETENTION_DAYS: RangeInclusive<u32> = 1..=3650;
|
|||||||
/// default on load (see [`Settings::load`]) rather than failing.
|
/// default on load (see [`Settings::load`]) rather than failing.
|
||||||
pub const DEEPSCRIPT_MODELS: [&str; 2] = ["premium", "premium_jade"];
|
pub const DEEPSCRIPT_MODELS: [&str; 2] = ["premium", "premium_jade"];
|
||||||
|
|
||||||
|
/// The languages (ISO 639-1) a call can be transcribed in, chosen per call
|
||||||
|
/// when its transcription is started. All are in DeepScript's
|
||||||
|
/// `GET /v1/languages`; its `"auto"` is not offered.
|
||||||
|
pub const CALL_LANGUAGES: [&str; 5] = ["de", "en", "es", "fr", "it"];
|
||||||
|
|
||||||
|
/// Checks a call language chosen in the UI; the error is shown as is.
|
||||||
|
pub fn check_call_language(language: &str) -> Result<(), String> {
|
||||||
|
if CALL_LANGUAGES.contains(&language) {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(format!("Unbekannte Sprache: {language}"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Default custom-vocabulary terms: short standalone German words/names
|
/// Default custom-vocabulary terms: short standalone German words/names
|
||||||
/// DeepScript otherwise tends to mistranscribe or drop.
|
/// DeepScript otherwise tends to mistranscribe or drop.
|
||||||
const DEFAULT_VOCABULARY: [&str; 5] = ["Tschüss", "Perfekt", "Servus", "Moin", "Euvino"];
|
const DEFAULT_VOCABULARY: [&str; 5] = ["Tschüss", "Perfekt", "Servus", "Moin", "Euvino"];
|
||||||
@@ -56,6 +70,9 @@ pub struct Settings {
|
|||||||
pub allowlist: Vec<String>,
|
pub allowlist: Vec<String>,
|
||||||
pub mic_device: Option<String>,
|
pub mic_device: Option<String>,
|
||||||
pub output_device: Option<String>,
|
pub output_device: Option<String>,
|
||||||
|
/// The language of the transcription started last (one of
|
||||||
|
/// [`CALL_LANGUAGES`]), preselected for the next call. Set by the app
|
||||||
|
/// when a transcription is started, not by the settings page.
|
||||||
pub language: String,
|
pub language: String,
|
||||||
pub deepscript_model: String,
|
pub deepscript_model: String,
|
||||||
/// Custom words/names submitted with every transcription (DeepScript's
|
/// Custom words/names submitted with every transcription (DeepScript's
|
||||||
@@ -146,12 +163,14 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The settings after the user saved `edited` over these: normalized
|
/// The settings after the user saved `edited` over these: normalized
|
||||||
/// (see [`normalize_vocabulary`]), checked, with the backend login
|
/// (see [`normalize_vocabulary`]), checked, with the backend login and
|
||||||
/// (which only the app changes) kept, so a settings page loaded before
|
/// the last-used language (which only the app changes) kept, so a
|
||||||
/// a login cannot undo it.
|
/// settings page loaded before a login or a transcription cannot undo
|
||||||
|
/// them.
|
||||||
pub fn edited(&self, mut edited: Settings) -> Result<Settings, String> {
|
pub fn edited(&self, mut edited: Settings) -> Result<Settings, String> {
|
||||||
edited.vocabulary = normalize_vocabulary(edited.vocabulary);
|
edited.vocabulary = normalize_vocabulary(edited.vocabulary);
|
||||||
edited.validate()?;
|
edited.validate()?;
|
||||||
|
edited.language = self.language.clone();
|
||||||
edited.backend_username = self.backend_username.clone();
|
edited.backend_username = self.backend_username.clone();
|
||||||
edited.backend_key_expires_at = self.backend_key_expires_at;
|
edited.backend_key_expires_at = self.backend_key_expires_at;
|
||||||
edited.backend_key_base_url = self.backend_key_base_url.clone();
|
edited.backend_key_base_url = self.backend_key_base_url.clone();
|
||||||
@@ -162,8 +181,9 @@ impl Settings {
|
|||||||
/// defaults; fields missing from the file take their default value. A
|
/// defaults; fields missing from the file take their default value. A
|
||||||
/// `deepscript_model` outside [`DEEPSCRIPT_MODELS`] (e.g. an older
|
/// `deepscript_model` outside [`DEEPSCRIPT_MODELS`] (e.g. an older
|
||||||
/// file's `"standard"`) falls back to the default instead of failing, and
|
/// file's `"standard"`) falls back to the default instead of failing, and
|
||||||
/// so does a `retention_days` outside [`RETENTION_DAYS`]; `vocabulary`
|
/// so does a `retention_days` outside [`RETENTION_DAYS`] and a
|
||||||
/// is normalized (see [`normalize_vocabulary`]).
|
/// `language` outside [`CALL_LANGUAGES`]; `vocabulary` is normalized
|
||||||
|
/// (see [`normalize_vocabulary`]).
|
||||||
pub fn load(path: &Path) -> Settings {
|
pub fn load(path: &Path) -> Settings {
|
||||||
let mut settings: Settings = fs::read_to_string(path)
|
let mut settings: Settings = fs::read_to_string(path)
|
||||||
.ok()
|
.ok()
|
||||||
@@ -172,6 +192,9 @@ impl Settings {
|
|||||||
if !DEEPSCRIPT_MODELS.contains(&settings.deepscript_model.as_str()) {
|
if !DEEPSCRIPT_MODELS.contains(&settings.deepscript_model.as_str()) {
|
||||||
settings.deepscript_model = Settings::default().deepscript_model;
|
settings.deepscript_model = Settings::default().deepscript_model;
|
||||||
}
|
}
|
||||||
|
if check_call_language(&settings.language).is_err() {
|
||||||
|
settings.language = Settings::default().language;
|
||||||
|
}
|
||||||
// 0 would delete all audio on the next pass.
|
// 0 would delete all audio on the next pass.
|
||||||
if !RETENTION_DAYS.contains(&settings.retention_days) {
|
if !RETENTION_DAYS.contains(&settings.retention_days) {
|
||||||
settings.retention_days = Settings::default().retention_days;
|
settings.retention_days = Settings::default().retention_days;
|
||||||
@@ -289,6 +312,51 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_five_call_languages_are_accepted() {
|
||||||
|
for language in CALL_LANGUAGES {
|
||||||
|
assert_eq!(check_call_language(language), Ok(()), "{language}");
|
||||||
|
}
|
||||||
|
assert_eq!(CALL_LANGUAGES, ["de", "en", "es", "fr", "it"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn another_call_language_is_refused() {
|
||||||
|
assert_eq!(
|
||||||
|
check_call_language("auto"),
|
||||||
|
Err("Unbekannte Sprache: auto".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
check_call_language("pt"),
|
||||||
|
Err("Unbekannte Sprache: pt".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_unknown_stored_language_falls_back_to_the_default() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let path = dir.path().join("settings.json");
|
||||||
|
fs::write(&path, r#"{"language": "auto"}"#).unwrap();
|
||||||
|
assert_eq!(Settings::load(&path).language, "de");
|
||||||
|
|
||||||
|
fs::write(&path, r#"{"language": "it"}"#).unwrap();
|
||||||
|
assert_eq!(Settings::load(&path).language, "it");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn an_edit_keeps_the_last_used_language_which_only_the_app_changes() {
|
||||||
|
let current = Settings {
|
||||||
|
language: "fr".into(),
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
let edited = Settings {
|
||||||
|
language: "de".into(),
|
||||||
|
..Settings::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(current.edited(edited).unwrap().language, "fr");
|
||||||
|
}
|
||||||
|
|
||||||
fn logged_in() -> Settings {
|
fn logged_in() -> Settings {
|
||||||
Settings {
|
Settings {
|
||||||
backend_username: Some("hinrichs".into()),
|
backend_username: Some("hinrichs".into()),
|
||||||
|
|||||||
Reference in New Issue
Block a user