Skip to content

Commit 0c00839

Browse files
Merge pull request #2685 from yashranaway/fix/caption-unicode
fix(desktop-gpui): count characters, not bytes, at caption boundaries
2 parents 90e4474 + 5b67cc3 commit 0c00839

2 files changed

Lines changed: 37 additions & 21 deletions

File tree

‎apps/desktop-gpui/src/transcription.rs‎

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ fn caption_boundary_word_is_weak(word: &CaptionWord) -> bool {
18091809
.collect::<String>()
18101810
.to_lowercase();
18111811

1812-
normalized.len() <= 1
1812+
normalized.chars().count() <= 1
18131813
|| matches!(
18141814
normalized.as_str(),
18151815
"an" | "as"
@@ -2313,21 +2313,44 @@ mod tests {
23132313

23142314
#[test]
23152315
fn caption_word_chunks_do_not_end_on_short_connector_when_more_words_follow() {
2316-
let words = [
2317-
"This", "is", "where", "we", "record", "I", "want", "clean", "captions",
2318-
]
2319-
.iter()
2320-
.enumerate()
2321-
.map(|(index, text)| word(text, index))
2322-
.collect::<Vec<_>>();
2316+
for connector in ["I", "à", "à,", "a\u{300}", "日"] {
2317+
let words = [
2318+
"This", "is", "where", "we", "record", connector, "want", "clean", "captions",
2319+
]
2320+
.iter()
2321+
.enumerate()
2322+
.map(|(index, text)| word(text, index))
2323+
.collect::<Vec<_>>();
23232324

2324-
let chunks = caption_word_chunks(&words);
2325+
let chunks = caption_word_chunks(&words);
23252326

2326-
assert_eq!(
2327-
caption_text_from_words(chunks[0]),
2328-
"This is where we record I want"
2329-
);
2330-
assert_eq!(caption_text_from_words(chunks[1]), "clean captions");
2327+
assert_eq!(
2328+
caption_text_from_words(chunks[0]),
2329+
format!("This is where we record {connector} want")
2330+
);
2331+
assert_eq!(caption_text_from_words(chunks[1]), "clean captions");
2332+
}
2333+
}
2334+
2335+
#[test]
2336+
fn caption_word_chunks_merge_short_tail_starting_with_connector() {
2337+
for connector in ["I", "à", "à,", "a\u{300}", "日"] {
2338+
let words = [
2339+
"These", "captions", "should", "stay", "grouped", "together", connector, "Paris",
2340+
]
2341+
.iter()
2342+
.enumerate()
2343+
.map(|(index, text)| word(text, index))
2344+
.collect::<Vec<_>>();
2345+
2346+
let chunks = caption_word_chunks(&words);
2347+
2348+
assert_eq!(chunks.len(), 1, "connector {connector}");
2349+
assert_eq!(
2350+
caption_text_from_words(chunks[0]),
2351+
format!("These captions should stay grouped together {connector} Paris")
2352+
);
2353+
}
23312354
}
23322355

23332356
// -- Model paths ----------------------------------------------------------

‎crates/verify/expectations.toml‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,6 @@ bound = { count = 1, missing = 30 }
172172
reason = "NEW: same as editing/mapping/duration-covered, end to end: a 1 s fullscreen text at 5.4 s and the clip trimmed to 3.2 s give a 4.2 s timeline, but the export stops at the first unmapped frame: 96 frames instead of 126, and the text card is never rendered"
173173
link = ""
174174

175-
[[xfail]]
176-
case = "captions/app/segmentation/unicode"
177-
class = "caption-segments"
178-
bound = { count = [1, 3] }
179-
reason = "NEW (minor): caption chunking decides that a boundary word is a weak one-letter word with String::len() (bytes), so a one-letter word outside ASCII such as the French preposition 'à' is not weak and a caption can end on it (apps/desktop-gpui/src/transcription.rs caption_boundary_word_is_weak). The case reports the first three failing token streams; an unexpected error from the product would add a problem beyond them. Repro: cargo test --manifest-path apps/desktop-gpui/Cargo.toml --bin cap-gpui segmentation_matches_reference_unicode -- --nocapture"
180-
link = ""
181-
182175
[[xfail]]
183176
case = "captions/legacy-migration/ends-at-timeline-end"
184177
class = "caption-migration"

0 commit comments

Comments
 (0)