Documentation Index
Fetch the complete documentation index at: https://mintlify.com/6xingyv/accompanist-lyrics-core/llms.txt
Use this file to discover all available pages before exploring further.
TTMLExporter serializes a SyncedLyrics object into a complete TTML XML document compatible with Apple Music’s internal lyrics format. It supports syllable-level <span> elements, multi-voice agent declarations for duets, background vocal spans, translation metadata, and automatic HTML-entity escaping — all without any external XML library dependency.
Signature
TTMLExporter is a Kotlin object (singleton) that implements ILyricsExporter:
SyncedLyrics instance; receive a fully-formed TTML XML string. If lyrics.lines is empty, the method returns an empty string immediately.
Usage
Output structure
The exported document always starts with an XML declaration and a<tt> root element carrying the required namespace declarations:
mm:ss.xxx notation (minutes, seconds, milliseconds).
The <body dur> value and <div end> value are both derived from the maximum end time across all lines. The <div begin> value is the start time of the first line.
KaraokeLine — syllable <p> elements
Each KaraokeLine.MainKaraokeLine becomes a <p> element whose children are individual <span> elements, one per KaraokeSyllable:
</span> tag to preserve word spacing. All spans and text content are written inline within the <p> element — there are no additional newlines between spans.
SyncedLine — plain <p> elements
A SyncedLine (no syllable data) is written as a <p> element with its text content inlined — no child <span> elements are added:
Translation spans
When any line carries atranslation string, a <span> with ttm:role="x-translation" and xml:lang="zh-CN" is appended at the end of the <p> element, after all syllable spans:
Background vocal spans (x-bg)
Background vocals stored as AccompanimentKaraokeLine entries are written as <span ttm:role="x-bg"> elements inside the parent <p>. Each background span contains its own syllable <span> children and an optional translation span:
Multi-voice support
TTMLExporter automatically detects whether the SyncedLyrics contains lines for two distinct voices. Detection scans all lines and checks whether both KaraokeAlignment.Start and KaraokeAlignment.End are present:
KaraokeAlignment.Start→ voice v1 (typically the leading/left vocal)KaraokeAlignment.End→ voice v2 (typically the secondary/right vocal)
<head><metadata> and every <p> for a main-line with an alignment value receives a ttm:agent attribute:
If only one alignment value is present in the file (e.g. all lines are
KaraokeAlignment.Start with no KaraokeAlignment.End), multi-voice detection returns false and no agent metadata or ttm:agent attributes are written.Special character escaping
All text content — both line content and translations — is HTML-entity escaped before being written to the XML document:| Raw character | Escaped form |
|---|---|
& | & |
< | < |
> | > |
SyncedLine with content = "Hello <World>" and translation = "你好 & 世界" produces:
Full example
Use cases
Lyricify → Apple Music
Parse a Lyricify Syllable file with
LyricifySyllableParser and export with TTMLExporter to produce an Apple Music–compatible TTML document.KRC → TTML
Parse a Kugou KRC file with
KugouKrcParser and export to TTML, converting Kugou karaoke timing to the Apple Music format in one step.For plain-text output that also preserves syllable timing, use
EnhancedLrcExporter. For standard LRC without syllable data, use LrcExporter.