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 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<String, String>,
|
||||
merges: &BTreeMap<String, String>,
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 call_view;
|
||||
pub mod capture;
|
||||
pub mod corrections;
|
||||
pub mod detect;
|
||||
pub mod http;
|
||||
pub mod merge;
|
||||
|
||||
@@ -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<String>,
|
||||
}
|
||||
|
||||
/// 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();
|
||||
|
||||
+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.
|
||||
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)]
|
||||
#[serde(default)]
|
||||
pub struct Settings {
|
||||
@@ -35,6 +56,12 @@ pub struct Settings {
|
||||
pub output_device: Option<String>,
|
||||
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<String>,
|
||||
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<Settings, String> {
|
||||
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<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)]
|
||||
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();
|
||||
|
||||
@@ -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<String> 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());
|
||||
|
||||
@@ -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<String>,
|
||||
}
|
||||
|
||||
/// Uploads an audio file to a remote speech-to-text service, waits for the
|
||||
|
||||
Reference in New Issue
Block a user