export interface LrcLine { time: number; text: string; } const STAMP = /\[(\d+):(\d{1,2}(?:\.\d+)?)\]/g; /** Parses LRC timed lyrics: metadata tags and untimed lines are skipped, output is sorted by time. */ export function parseLrc(text: string): LrcLine[] { const lines: LrcLine[] = []; for (const raw of text.split(/\r?\n/)) { const stamps = [...raw.matchAll(STAMP)]; if (stamps.length === 0) continue; const lyric = raw.replace(STAMP, "").trim(); for (const [, min, sec] of stamps) { lines.push({ time: Math.round((Number(min) * 60 + Number(sec)) * 1000) / 1000, text: lyric }); } } return lines.sort((a, b) => a.time - b.time); }