Skip to content

syncalong.formatter

Render aligned lyrics as an LRC document with [mm:ss.xx] timestamps.

formatter

Format aligned lyrics as LRC (standard timed lyrics format).

format_lrc

format_lrc(timed_lines: list[tuple[LyricLine, float | None]]) -> str

Render aligned lyrics as an LRC document.

Lines with no timestamp are emitted without a time tag (some players show them statically). Blank lines become empty timed lines to preserve the song's visual structure.

Parameters:

Name Type Description Default
timed_lines list[tuple[LyricLine, float | None]]

(LyricLine, timestamp_or_None) pairs in order.

required

Returns:

Type Description
str

The LRC document, newline-terminated.

Source code in src/syncalong/formatter.py
def format_lrc(
    timed_lines: list[tuple[LyricLine, float | None]],
) -> str:
    """Render aligned lyrics as an LRC document.

    Lines with no timestamp are emitted without a time tag (some players show
    them statically). Blank lines become empty timed lines to preserve the
    song's visual structure.

    Args:
        timed_lines: ``(LyricLine, timestamp_or_None)`` pairs in order.

    Returns:
        The LRC document, newline-terminated.
    """
    parts: list[str] = []

    for line, ts in timed_lines:
        if ts is not None:
            tag = _seconds_to_lrc(ts)
            text = line.raw if not line.is_blank else ""
            parts.append(f"{tag} {text}")
        else:
            # No timestamp available — emit raw text without tag
            if line.is_blank:
                parts.append("")
            else:
                parts.append(line.raw)

    return "\n".join(parts) + "\n"