feat #14740: transcription model choice, vocabulary and short-word corrections
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ use std::collections::BTreeMap;
|
|||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::corrections::correct_segment_text;
|
||||||
use crate::merge;
|
use crate::merge;
|
||||||
use crate::model::{Call, CallId, CallStatus, Segment, Speaker};
|
use crate::model::{Call, CallId, CallStatus, Segment, Speaker};
|
||||||
|
|
||||||
@@ -176,13 +177,18 @@ pub struct CallDetail {
|
|||||||
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`]).
|
/// (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(
|
pub fn of(
|
||||||
call: &Call,
|
call: &Call,
|
||||||
segments: &[Segment],
|
segments: &[Segment],
|
||||||
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,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let segments = merge::apply_merges(segments, merges)
|
let segments = merge::apply_merges(segments, merges)
|
||||||
.iter()
|
.iter()
|
||||||
@@ -191,7 +197,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: segment.text.clone(),
|
text: correct_segment_text(&segment.text, language),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Self {
|
Self {
|
||||||
@@ -500,6 +506,7 @@ mod tests {
|
|||||||
names.clone(),
|
names.clone(),
|
||||||
&BTreeMap::new(),
|
&BTreeMap::new(),
|
||||||
BACKEND,
|
BACKEND,
|
||||||
|
"de",
|
||||||
);
|
);
|
||||||
|
|
||||||
let lines: Vec<_> = detail
|
let lines: Vec<_> = detail
|
||||||
@@ -550,6 +557,7 @@ mod tests {
|
|||||||
names,
|
names,
|
||||||
&merges,
|
&merges,
|
||||||
BACKEND,
|
BACKEND,
|
||||||
|
"de",
|
||||||
);
|
);
|
||||||
|
|
||||||
let lines: Vec<_> = detail
|
let lines: Vec<_> = detail
|
||||||
@@ -601,8 +609,14 @@ mod tests {
|
|||||||
c.transcribed_at = Some(at(10, 20, 0));
|
c.transcribed_at = Some(at(10, 20, 0));
|
||||||
let merges = keys(&[("remote:2", "remote:1")]);
|
let merges = keys(&[("remote:2", "remote:1")]);
|
||||||
|
|
||||||
let value =
|
let value = serde_json::to_value(CallDetail::of(
|
||||||
serde_json::to_value(CallDetail::of(&c, &[], BTreeMap::new(), &merges, BACKEND))
|
&c,
|
||||||
|
&[],
|
||||||
|
BTreeMap::new(),
|
||||||
|
&merges,
|
||||||
|
BACKEND,
|
||||||
|
"de",
|
||||||
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@@ -637,12 +651,22 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn detail_with_language(
|
||||||
|
c: &Call,
|
||||||
|
segments: &[Segment],
|
||||||
|
names: &[(&str, &str)],
|
||||||
|
language: &str,
|
||||||
|
) -> CallDetail {
|
||||||
CallDetail::of(
|
CallDetail::of(
|
||||||
c,
|
c,
|
||||||
segments,
|
segments,
|
||||||
keys(names),
|
keys(names),
|
||||||
&keys(&[("remote:2", "remote:1")]),
|
&keys(&[("remote:2", "remote:1")]),
|
||||||
BACKEND,
|
BACKEND,
|
||||||
|
language,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,4 +728,39 @@ mod tests {
|
|||||||
}
|
}
|
||||||
assert_eq!(NO_TRANSCRIPT, "Kein Transkript zum Hochladen");
|
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}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ pub mod audio;
|
|||||||
pub mod backend;
|
pub mod backend;
|
||||||
pub mod call_view;
|
pub mod call_view;
|
||||||
pub mod capture;
|
pub mod capture;
|
||||||
|
pub mod corrections;
|
||||||
pub mod detect;
|
pub mod detect;
|
||||||
pub mod http;
|
pub mod http;
|
||||||
pub mod merge;
|
pub mod merge;
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ pub struct PipelineOptions {
|
|||||||
/// ISO 639-1 code, or `"auto"`.
|
/// ISO 639-1 code, or `"auto"`.
|
||||||
pub language: String,
|
pub language: String,
|
||||||
pub deepscript_model: String,
|
pub deepscript_model: String,
|
||||||
|
/// Custom words/names submitted with both tracks (DeepScript's
|
||||||
|
/// `vocabulary` field).
|
||||||
|
pub vocabulary: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Everything a pipeline run can fail with.
|
/// Everything a pipeline run can fail with.
|
||||||
@@ -140,6 +143,7 @@ async fn transcribe(
|
|||||||
language: opts.language.clone(),
|
language: opts.language.clone(),
|
||||||
model: opts.deepscript_model.clone(),
|
model: opts.deepscript_model.clone(),
|
||||||
single_speaker,
|
single_speaker,
|
||||||
|
vocabulary: opts.vocabulary.clone(),
|
||||||
};
|
};
|
||||||
let (mic_opts, out_opts) = (track_opts(true), track_opts(false));
|
let (mic_opts, out_opts) = (track_opts(true), track_opts(false));
|
||||||
let (mic_job, out_job) = tokio::join!(
|
let (mic_job, out_job) = tokio::join!(
|
||||||
@@ -431,6 +435,7 @@ mod tests {
|
|||||||
PipelineOptions {
|
PipelineOptions {
|
||||||
language: "de".to_string(),
|
language: "de".to_string(),
|
||||||
deepscript_model: "premium".to_string(),
|
deepscript_model: "premium".to_string(),
|
||||||
|
vocabulary: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,6 +552,7 @@ mod tests {
|
|||||||
language: "de".to_string(),
|
language: "de".to_string(),
|
||||||
model: "premium".to_string(),
|
model: "premium".to_string(),
|
||||||
single_speaker,
|
single_speaker,
|
||||||
|
vocabulary: Vec::new(),
|
||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
fake.submitted(),
|
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]
|
#[tokio::test]
|
||||||
async fn pipeline_transcription_failure_sets_failed_keeps_audio() {
|
async fn pipeline_transcription_failure_sets_failed_keeps_audio() {
|
||||||
let f = fixture();
|
let f = fixture();
|
||||||
|
|||||||
+181
-6
@@ -27,6 +27,27 @@ pub const START_AFTER_SECS: RangeInclusive<u64> = 1..=30;
|
|||||||
/// splits a call, e.g. when the headset is switched.
|
/// splits a call, e.g. when the headset is switched.
|
||||||
pub const END_AFTER_SECS: RangeInclusive<u64> = 3..=120;
|
pub const END_AFTER_SECS: RangeInclusive<u64> = 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)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
@@ -35,6 +56,12 @@ pub struct Settings {
|
|||||||
pub output_device: Option<String>,
|
pub output_device: Option<String>,
|
||||||
pub language: String,
|
pub language: String,
|
||||||
pub deepscript_model: 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<String>,
|
||||||
pub retention_days: u32,
|
pub retention_days: u32,
|
||||||
pub autostart: bool,
|
pub autostart: bool,
|
||||||
pub start_after_secs: u64,
|
pub start_after_secs: u64,
|
||||||
@@ -57,6 +84,7 @@ impl Default for Settings {
|
|||||||
output_device: None,
|
output_device: None,
|
||||||
language: "de".to_string(),
|
language: "de".to_string(),
|
||||||
deepscript_model: "premium".to_string(),
|
deepscript_model: "premium".to_string(),
|
||||||
|
vocabulary: DEFAULT_VOCABULARY.iter().map(|s| s.to_string()).collect(),
|
||||||
retention_days: 7,
|
retention_days: 7,
|
||||||
autostart: true,
|
autostart: true,
|
||||||
start_after_secs: 3,
|
start_after_secs: 3,
|
||||||
@@ -85,13 +113,35 @@ impl Settings {
|
|||||||
END_AFTER_SECS.end()
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The settings after the user saved `edited` over these: checked, with
|
/// The settings after the user saved `edited` over these: normalized
|
||||||
/// the backend login (which only the app changes) kept, so a settings
|
/// (see [`normalize_vocabulary`]), checked, with the backend login
|
||||||
/// page loaded before a login cannot undo it.
|
/// (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<Settings, String> {
|
pub fn edited(&self, mut edited: Settings) -> Result<Settings, String> {
|
||||||
|
edited.vocabulary = normalize_vocabulary(edited.vocabulary);
|
||||||
edited.validate()?;
|
edited.validate()?;
|
||||||
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;
|
||||||
@@ -100,12 +150,20 @@ impl Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reads the settings file. A missing or unreadable file yields the
|
/// 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 {
|
pub fn load(path: &Path) -> Settings {
|
||||||
fs::read_to_string(path)
|
let mut settings: Settings = fs::read_to_string(path)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|json| serde_json::from_str(&json).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
|
/// 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<String>) -> Vec<String> {
|
||||||
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -143,6 +218,10 @@ mod tests {
|
|||||||
assert_eq!(s.output_device, None);
|
assert_eq!(s.output_device, None);
|
||||||
assert_eq!(s.language, "de");
|
assert_eq!(s.language, "de");
|
||||||
assert_eq!(s.deepscript_model, "premium");
|
assert_eq!(s.deepscript_model, "premium");
|
||||||
|
assert_eq!(
|
||||||
|
s.vocabulary,
|
||||||
|
vec!["Tschüss", "Perfekt", "Servus", "Moin", "Euvino"]
|
||||||
|
);
|
||||||
assert_eq!(s.retention_days, 7);
|
assert_eq!(s.retention_days, 7);
|
||||||
assert!(s.autostart);
|
assert!(s.autostart);
|
||||||
assert_eq!(s.start_after_secs, 3);
|
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 {
|
fn logged_in() -> Settings {
|
||||||
Settings {
|
Settings {
|
||||||
backend_username: Some("hinrichs".into()),
|
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]
|
#[test]
|
||||||
fn settings_load_missing_file_returns_default() {
|
fn settings_load_missing_file_returns_default() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
|||||||
@@ -201,6 +201,15 @@ impl Transcriber for DeepScript {
|
|||||||
value: "1".to_string(),
|
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<String> always serializes"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let req = HttpRequest {
|
let req = HttpRequest {
|
||||||
method: Method::Post,
|
method: Method::Post,
|
||||||
@@ -385,6 +394,7 @@ mod tests {
|
|||||||
language: language.to_string(),
|
language: language.to_string(),
|
||||||
model: model.to_string(),
|
model: model.to_string(),
|
||||||
single_speaker,
|
single_speaker,
|
||||||
|
vocabulary: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,6 +449,57 @@ mod tests {
|
|||||||
transport.assert_done();
|
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]
|
#[tokio::test]
|
||||||
async fn submit_without_hint_for_output_track() {
|
async fn submit_without_hint_for_output_track() {
|
||||||
let transport = Arc::new(FakeTransport::new());
|
let transport = Arc::new(FakeTransport::new());
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ pub struct TranscribeOptions {
|
|||||||
/// the user) — the output track may have several, so this is left
|
/// the user) — the output track may have several, so this is left
|
||||||
/// unset there.
|
/// unset there.
|
||||||
pub single_speaker: bool,
|
pub single_speaker: bool,
|
||||||
|
/// Custom words/names to bias the transcription towards (DeepScript's
|
||||||
|
/// `vocabulary` field); empty omits the field entirely.
|
||||||
|
pub vocabulary: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uploads an audio file to a remote speech-to-text service, waits for the
|
/// Uploads an audio file to a remote speech-to-text service, waits for the
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> {
|
|||||||
let opts = PipelineOptions {
|
let opts = PipelineOptions {
|
||||||
language: settings.language,
|
language: settings.language,
|
||||||
deepscript_model: settings.deepscript_model,
|
deepscript_model: settings.deepscript_model,
|
||||||
|
vocabulary: settings.vocabulary,
|
||||||
};
|
};
|
||||||
// A fresh client per run, so a key changed in the settings applies to
|
// A fresh client per run, so a key changed in the settings applies to
|
||||||
// the next run.
|
// the next run.
|
||||||
|
|||||||
@@ -647,7 +647,14 @@ impl AppState {
|
|||||||
let segments = self.store.segments(id).map_err(|e| e.to_string())?;
|
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 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 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);
|
detail.uploading = self.is_uploading(id);
|
||||||
Ok(detail)
|
Ok(detail)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export interface Settings {
|
|||||||
output_device: string | null
|
output_device: string | null
|
||||||
language: string
|
language: string
|
||||||
deepscript_model: string
|
deepscript_model: string
|
||||||
|
/** Custom words/names submitted with every transcription. */
|
||||||
|
vocabulary: string[]
|
||||||
retention_days: number
|
retention_days: number
|
||||||
autostart: boolean
|
autostart: boolean
|
||||||
start_after_secs: number
|
start_after_secs: number
|
||||||
|
|||||||
@@ -43,6 +43,10 @@
|
|||||||
]
|
]
|
||||||
|
|
||||||
let settings = $state<Settings | null>(null)
|
let settings = $state<Settings | null>(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<Devices>({ inputs: [], outputs: [] })
|
let devices = $state<Devices>({ inputs: [], outputs: [] })
|
||||||
let keySaved = $state<Record<Service, boolean>>({ deepscript: false })
|
let keySaved = $state<Record<Service, boolean>>({ deepscript: false })
|
||||||
let keyInput = $state<Record<Service, string>>({ deepscript: '' })
|
let keyInput = $state<Record<Service, string>>({ deepscript: '' })
|
||||||
@@ -207,6 +211,7 @@
|
|||||||
async function load() {
|
async function load() {
|
||||||
try {
|
try {
|
||||||
settings = await getSettings()
|
settings = await getSettings()
|
||||||
|
vocabularyText = settings.vocabulary.join('\n')
|
||||||
for (const { id } of services) keySaved[id] = await hasApiKey(id)
|
for (const { id } of services) keySaved[id] = await hasApiKey(id)
|
||||||
devices = await listDevices()
|
devices = await listDevices()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -268,7 +273,12 @@
|
|||||||
if (!Number.isInteger(settings.retention_days) || settings.retention_days < 1) {
|
if (!Number.isInteger(settings.retention_days) || settings.retention_days < 1) {
|
||||||
throw 'Aufbewahrung: bitte eine ganze Zahl ab 1 eingeben'
|
throw 'Aufbewahrung: bitte eine ganze Zahl ab 1 eingeben'
|
||||||
}
|
}
|
||||||
|
settings.vocabulary = vocabularyText.split('\n')
|
||||||
await saveSettings($state.snapshot(settings))
|
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() {
|
async function runTest() {
|
||||||
@@ -474,6 +484,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section class="card">
|
||||||
|
<h2>Transkription</h2>
|
||||||
|
<div class="grid">
|
||||||
|
<label for="deepscript-model">Modell</label>
|
||||||
|
<select id="deepscript-model" bind:value={settings.deepscript_model}>
|
||||||
|
<option value="premium">Premium</option>
|
||||||
|
<option value="premium_jade">Premium Jade</option>
|
||||||
|
</select>
|
||||||
|
<span></span>
|
||||||
|
<span class="muted">Gilt für neue Transkriptionen.</span>
|
||||||
|
</div>
|
||||||
|
<label for="vocabulary" class="vocabulary-label">Vokabular (ein Begriff pro Zeile)</label>
|
||||||
|
<textarea id="vocabulary" rows="6" bind:value={vocabularyText}></textarea>
|
||||||
|
<p class="muted">
|
||||||
|
Namen, Firmen- und Produktbegriffe, die oft falsch erkannt werden.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<h2>Updates</h2>
|
<h2>Updates</h2>
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
@@ -575,6 +603,21 @@
|
|||||||
justify-self: start;
|
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 {
|
.hint {
|
||||||
margin: 12px 0;
|
margin: 12px 0;
|
||||||
padding: 8px 10px;
|
padding: 8px 10px;
|
||||||
|
|||||||
Reference in New Issue
Block a user