
On-device pronunciation resolution and caption formatting for lyrics: multilingual readings (Mandarin mainland/Taiwan, Hong Kong Cantonese, Japanese), contextual overrides, alignment to lyric ranges, optional offline data packs.
Accompanist includes a group of libraries:
lyrics-core — Parse lyrics files, retain timing and metadata, and export to other formats.lyrics-ui — Display synchronized lyrics with Compose Multiplatform.lyrics-phonetics — Resolve pronunciation on device and format captions for lyrics.This repository hosts the lyrics-phonetics code, a Kotlin Multiplatform library for Android, JVM and iOS.
Add the runtime and the data packs you need to your build.gradle.kts:
dependencies {
implementation("com.mocharealm.accompanist:lyrics-phonetics-runtime:0.1.0")
implementation("com.mocharealm.accompanist:lyrics-phonetics-data-mandarin:0.1.0")
implementation("com.mocharealm.accompanist:lyrics-phonetics-data-cantonese:0.1.0")
implementation("com.mocharealm.accompanist:lyrics-phonetics-data-japanese:0.1.0")
}For Kotlin Multiplatform, add these to commonMain.dependencies. Include only the language packs you need.
On Android, keep dictionary assets uncompressed so the loader can map them:
android {
androidResources { noCompress += "lpd" }
}On iOS, copy the data packs and their licenses from the resources ZIP into the app bundle.
import com.mocharealm.accompanist.lyrics.phonetics.*
import com.mocharealm.accompanist.lyrics.phonetics.data.*
// JVM example. On Android use AndroidPackLoader(context);
// on iOS use IosBundlePackLoader().
val loader = SharedPackLoader(ClasspathPackLoader())
val engine = PhoneticEngine(listOf(
MandarinData.mainland(loader),
MandarinData.taiwan(loader),
CantoneseData.hongKong(loader),
JapaneseData.japanese(loader),
))
val result = engine.parse(
"银行行走",
ParseOptions(defaultLocale = ReadingLocale.MANDARIN_CN),
)
println(AsciiFormatter().format(result).latin) // yin hang xing zou
println(AsciiFormatter(FormatOptions(tones = ToneStyle.NUMBERS)).format(result).latin)
// yin2 hang2 xing2 zou3Contributions are welcome! Please open an issue before proposing major changes.
Code is licensed under Apache License 2.0. See LICENSE. Language data has separate licenses; see data sources and licenses and retain the bundled notices.
Accompanist includes a group of libraries:
lyrics-core — Parse lyrics files, retain timing and metadata, and export to other formats.lyrics-ui — Display synchronized lyrics with Compose Multiplatform.lyrics-phonetics — Resolve pronunciation on device and format captions for lyrics.This repository hosts the lyrics-phonetics code, a Kotlin Multiplatform library for Android, JVM and iOS.
Add the runtime and the data packs you need to your build.gradle.kts:
dependencies {
implementation("com.mocharealm.accompanist:lyrics-phonetics-runtime:0.1.0")
implementation("com.mocharealm.accompanist:lyrics-phonetics-data-mandarin:0.1.0")
implementation("com.mocharealm.accompanist:lyrics-phonetics-data-cantonese:0.1.0")
implementation("com.mocharealm.accompanist:lyrics-phonetics-data-japanese:0.1.0")
}For Kotlin Multiplatform, add these to commonMain.dependencies. Include only the language packs you need.
On Android, keep dictionary assets uncompressed so the loader can map them:
android {
androidResources { noCompress += "lpd" }
}On iOS, copy the data packs and their licenses from the resources ZIP into the app bundle.
import com.mocharealm.accompanist.lyrics.phonetics.*
import com.mocharealm.accompanist.lyrics.phonetics.data.*
// JVM example. On Android use AndroidPackLoader(context);
// on iOS use IosBundlePackLoader().
val loader = SharedPackLoader(ClasspathPackLoader())
val engine = PhoneticEngine(listOf(
MandarinData.mainland(loader),
MandarinData.taiwan(loader),
CantoneseData.hongKong(loader),
JapaneseData.japanese(loader),
))
val result = engine.parse(
"银行行走",
ParseOptions(defaultLocale = ReadingLocale.MANDARIN_CN),
)
println(AsciiFormatter().format(result).latin) // yin hang xing zou
println(AsciiFormatter(FormatOptions(tones = ToneStyle.NUMBERS)).format(result).latin)
// yin2 hang2 xing2 zou3Contributions are welcome! Please open an issue before proposing major changes.
Code is licensed under Apache License 2.0. See LICENSE. Language data has separate licenses; see data sources and licenses and retain the bundled notices.