Lyrics for CJK languages often include phonetic annotations — pinyin for Mandarin, romaji or furigana for Japanese, romanisation for Korean — to help listeners who cannot read the script. Accompanist Lyrics Core provides theDocumentation 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.
PhoneticProvider interface so you can attach a romanisation library of your choice and have it populate phonetic fields automatically whenever the source TTML file does not already carry that data.
The PhoneticProvider interface
phoneticLevel, then implement getPhonetic to delegate to whatever romanisation library your project uses.
Choosing a PhoneticLevel
PhoneticLevel controls when getPhonetic is called and where the result is stored in the parsed model.
| Level | Called | Stored on |
|---|---|---|
PhoneticLevel.LINE | Once per lyrics line | KaraokeLine.phonetic |
PhoneticLevel.SYLLABLE | Once per syllable | KaraokeSyllable.phonetic |
LINE granularity
Best when your romanisation library works on whole sentences and produces a single string for the entire line. Lower call overhead.
SYLLABLE granularity
Best for karaoke highlighting where each syllable needs its own phonetic label displayed as the syllable plays. Higher fidelity, more calls.
PhoneticProvider is a fallback mechanism — it is invoked only when the source TTML file does not already contain phonetic data for that line or syllable. Existing phonetics in the file are always preserved.Implementing a provider
The implementation is deliberately thin: declare the level, then forwardgetPhonetic to whatever library handles your target script.
Line-level example (Mandarin pinyin):
Configuring your provider
If you are using
TTMLParser on its own, pass your provider via the fallbackPhoneticProvider constructor parameter:val parser = TTMLParser(fallbackPhoneticProvider = PinyinProvider())
val lyrics = parser.parse(ttmlContent)
When using
AutoParser for automatic format detection, the fallbackPhoneticProvider is forwarded automatically to the internal TTMLParser instance:val autoParser = AutoParser(fallbackPhoneticProvider = PinyinProvider())
val lyrics = autoParser.parse(rawContent)
The
fallbackPhoneticProvider passed to AutoParser is forwarded only to the internally created TTMLParser. If you supply a custom parser list, create your TTMLParser with the provider explicitly included.Accessing phonetics from the parsed result
After parsing, phonetic strings are available directly on the model objects:KaraokeLine.phonetic and KaraokeSyllable.phonetic are nullable String?. When the TTML contained phonetic data natively and no fallback was needed, both provider levels will still leave those pre-existing strings intact.
Scope and limitations
Purely a fallback
The provider is skipped whenever the TTML source already has phonetic annotations, so importing pre-annotated TTML files will never accidentally overwrite existing data.
Any romanisation library
The interface makes no assumptions about which library you use — integrate any pinyin, romaji, hangul romanisation, or transliteration package that fits your build target.