Skip to content

Commit 021929d

Browse files
committed
fix(lyrics): honor TTML word timing placeholders
1 parent 2f1ab4d commit 021929d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

services/lyrics/ttml.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ const lineEndOf = (line: LyricLine): number => {
312312
return line.time;
313313
};
314314

315+
const lineStartOf = (time: number, end: number, words: LyricWord[]): number => {
316+
const first = words[0];
317+
if (!first) return time;
318+
if (first.startTime <= time) return time;
319+
if (end > time && end >= first.startTime) return time;
320+
return first.startTime;
321+
};
322+
315323
const CJK_SCRIPT_REGEX =
316324
/\p{Script=Han}|\p{Script=Hiragana}|\p{Script=Katakana}|\p{Script=Hangul}/u;
317325
const PUNCT_REGEX = /^[^\p{L}\p{N}]+$/u;
@@ -565,13 +573,14 @@ const parseP = (item: any, rootMode?: Mode, scope: Scope = {}): Entry[] => {
565573
}
566574

567575
if (hasMain) {
576+
const mainTime = lineStartOf(time, pEnd, mainWords);
568577
const line: LyricLine = {
569578
key,
570-
time,
579+
time: mainTime,
571580
text: text || mainWords.map((word) => word.text).join(""),
572581
};
573582

574-
if (pEnd > time) line.endTime = pEnd;
583+
if (pEnd > mainTime) line.endTime = pEnd;
575584

576585
if (mode === "word" && mainWords.length > 0) {
577586
line.words = mainWords;

0 commit comments

Comments
 (0)