native-lyrics-tools
Version:
A JavaScript library for parsing and generating various lyric formats.
23 lines (18 loc) • 686 B
JavaScript
const MAX_TIME = 60039999; // 999:99.999
export function processLyrics(lines) {
lines.sort((a, b) => {
const aTime = a.words?.[0]?.start_time ?? 0;
const bTime = b.words?.[0]?.start_time ?? 0;
return aTime - bTime;
});
for (const line of lines) {
const firstWord = line.words[0];
const lastWord = line.words[line.words.length - 1];
line.start_time = Math.min(firstWord?.start_time ?? 0, MAX_TIME);
line.end_time = Math.min(lastWord?.end_time ?? 0, MAX_TIME);
for (const word of line.words) {
word.start_time = Math.min(word.start_time, MAX_TIME);
word.end_time = Math.min(word.end_time, MAX_TIME);
}
}
}