Skip to content

Commit 3633e3c

Browse files
Google Team Membercopybara-github
authored andcommitted
fix(cli): keep punctuation-only speaker turns in tts --multi-speaker
Bounding `lineMarkerStart` at the previous label also made "only whitespace since the previous label" count as the start of a line, so a punctuation-only turn after a label on the same line was read as the next label's list marker and dropped with it (`Alice: ... Bob: Yes?`, `Alice: โ€” Bob: Sorry, go on.`, and `Alice: ?! Bob: What?` each sent only Bob's turn). Judge the line start on the whole text (`text[:floor+len(rest)]`) for every marker. The scan still stops at the previous label (`floor`), so emoji names (`๐Ÿ˜€: ๐Ÿค–:`) do not overlap or panic. PiperOrigin-RevId: 994686637
1 parent 1f78c8a commit 3633e3c

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

โ€Žinternal/cli/custom/custom_test.goโ€Ž

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,13 @@ func TestSpeakerTurns(t *testing.T) {
516516
{"Alice: 42. Bob: That is correct.", []string{"Alice", "Bob"}, []speakerTurn{turn("Alice", "42."), turn("Bob", "That is correct.")}},
517517
// A combining mark is part of the word: neither "\u0936\u094d\u0930\u0940\u0930\u093e\u092e:" nor "\u0930\u093e\u092e\u0940:" holds a label for "\u0930\u093e\u092e".
518518
{"Alice: \u0936\u094d\u0930\u0940\u0930\u093e\u092e: \u0930\u093e\u092e\u0940: hi. \u0930\u093e\u092e: yo.", []string{"Alice", "\u0930\u093e\u092e"}, []speakerTurn{turn("Alice", "\u0936\u094d\u0930\u0940\u0930\u093e\u092e: \u0930\u093e\u092e\u0940: hi."), turn("\u0930\u093e\u092e", "yo.")}},
519-
// Marker scanning stops at the previous label: names made of marker runes
520-
// stay labels, and a marker right after an empty label goes with the next.
519+
// Marker scanning stops at the previous label, so names made of marker
520+
// runes stay labels; a punctuation-only turn after a label is kept.
521521
{"\U0001F600: \U0001F916: hi.", []string{"\U0001F600", "\U0001F916"}, []speakerTurn{turn("\U0001F916", "hi.")}},
522522
{"\U0001F600: hi.\n\U0001F916: yo.", []string{"\U0001F600", "\U0001F916"}, []speakerTurn{turn("\U0001F600", "hi."), turn("\U0001F916", "yo.")}},
523-
{"Alice: - Bob: yo.", []string{"Alice", "Bob"}, []speakerTurn{bob}},
523+
{"Alice: - Bob: yo.", []string{"Alice", "Bob"}, []speakerTurn{turn("Alice", "-"), bob}},
524+
{"Alice: ... Bob: yo.", []string{"Alice", "Bob"}, []speakerTurn{turn("Alice", "..."), bob}},
525+
{"Alice: \u2014 Bob: yo.", []string{"Alice", "Bob"}, []speakerTurn{turn("Alice", "\u2014"), bob}},
524526
// "Annual:" is not a label for "Ann"; an undeclared "Carol:" stays in the turn.
525527
{"Ann: Annual: report. Carol: yes. Bo: ok.", []string{"Ann", "Bo"}, []speakerTurn{turn("Ann", "Annual: report. Carol: yes."), turn("Bo", "ok.")}},
526528
// The longer name wins over a declared prefix of it.

โ€Žinternal/cli/custom/tts.goโ€Ž

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,23 +264,21 @@ func isMarkerRune(r rune) bool {
264264
// the label at start begins ("- Alice:", "> Alice:", "โ€œAlice:", "1. Alice:"),
265265
// so the marker goes with the label instead of the previous turn or the text
266266
// before the first label. Without one, it returns start: punctuation or a
267-
// number after words on the same line ("hi. - Bob:", "Alice: 42. Bob:") stays
268-
// in the previous turn. The scan stops at floor, the end of the previous
269-
// label, so a name made of marker runes ("๐Ÿ˜€: ๐Ÿค–:") is never claimed as the
270-
// next label's marker.
267+
// number after words or a label on the same line ("hi. - Bob:",
268+
// "Alice: 42. Bob:", "Alice: ... Bob:") stays in the previous turn. The scan
269+
// stops at floor, the end of the previous label, so a name made of marker
270+
// runes ("๐Ÿ˜€: ๐Ÿค–:") is never claimed as the next label's marker; the line
271+
// start is still judged on the whole text.
271272
func lineMarkerStart(text string, floor, start int) int {
272273
before := strings.TrimRightFunc(text[floor:start], isHorizontalSpace)
273274
rest := strings.TrimRightFunc(before, isMarkerRune)
274275
if rest == before {
275276
return start
276277
}
277-
check := rest
278278
if marker := before[len(rest):]; marker == "." || marker == ")" {
279-
if digits := strings.TrimRightFunc(rest, unicode.IsDigit); len(digits) < len(rest) {
280-
rest, check = digits, text[:floor+len(digits)]
281-
}
279+
rest = strings.TrimRightFunc(rest, unicode.IsDigit)
282280
}
283-
if line := strings.TrimRightFunc(check, isHorizontalSpace); line != "" {
281+
if line := strings.TrimRightFunc(text[:floor+len(rest)], isHorizontalSpace); line != "" {
284282
if last, _ := utf8.DecodeLastRuneInString(line); !isLineBreak(last) {
285283
return start
286284
}

0 commit comments

Comments
ย (0)