Quick Start
AMLL provides two npm packages for lyric format parsing and serialization:
- @applemusic-like-lyrics/lyric
Parsing and generation for mainstream lyric formats such as LRC, YRC, and LQE. TTML parsing/serialization in this package internally relies on
@applemusic-like-lyrics/ttml. - @applemusic-like-lyrics/ttml Dedicated TTML parsing and serialization library with the most detailed TTML feature support.
Lyric Package
Section titled “Lyric Package”npm install @applemusic-like-lyrics/lyricpnpm add @applemusic-like-lyrics/lyricyarn add @applemusic-like-lyrics/lyricSupported formats in the Lyric package:
| Format | Extension | Parse | Stringify |
|---|---|---|---|
| TTML | .ttml | parseTTML | stringifyTTML |
| LRC | .lrc | parseLrc | stringifyLrc |
| LRC A2 | .lrc, .alrc | parseLrcA2 | stringifyLrcA2 |
| NetEase YRC | .yrc | parseYrc | stringifyYrc |
| QQ QRC | .qrc | parseQrc | stringifyQrc |
| EsLyric | .lrc, .eslrc | parseEslrc | stringifyEslrc |
| ASS subtitle | .ass | Not supported | stringifyAss |
| Lyricify Lines | .lyl | parseLyl | stringifyLyl |
| Lyricify Syllable | .lys | parseLys | stringifyLys |
| Lyricify Quick Export | .lqe | parseLqe | stringifyLqe |
All parse and stringify methods above are synchronous.
Except TTML, parse functions take a string and return LyricLine[]. Stringify functions take a lyric object array and return a string.
For TTML, parse output and stringify input are not LyricLine[], but a TTMLLyric object with metadata. Also, TTML parse/stringify in the Lyric package is browser-only. For Node.js usage or advanced TTML data, use the dedicated TTML package below.
The Lyric package also supports decryption/encryption for QQ Music encrypted QRC payloads: decryptQrcHex and encryptQrcHex.
For format details, see Lyric Formats.
TTML Package
Section titled “TTML Package”npm install @applemusic-like-lyrics/ttmlpnpm add @applemusic-like-lyrics/ttmlyarn add @applemusic-like-lyrics/ttmlThe TTML package provides TTML parsing and serialization. For format details, see TTML Format.
It supports two usage modes: class mode and function mode.
Class Mode
Section titled “Class Mode”The TTML package provides two classes: TTMLParser for parsing and TTMLGenerator for generation. Both also provide static shortcuts.
import { TTMLParser, TTMLGenerator } from "@applemusic-like-lyrics/ttml";
const parser = new TTMLParser();const ttmlObject = parser.parse("Some TTML string...");
const _ttmlObject = TTMLParser.parse("Some TTML string...");
const generator = new TTMLGenerator();const ttmlString = generator.generate(ttmlObject);
const _ttmlString = TTMLGenerator.generate(ttmlObject);By default, these classes are browser-oriented. TTMLParser uses DOMParser, and TTMLGenerator uses XMLSerializer and document.implementation. For Node.js, provide implementations explicitly, for example with @xmldom/xmldom:
import { TTMLParser, TTMLGenerator } from "@applemusic-like-lyrics/ttml";import { DOMParser, DOMImplementation, XMLSerializer } from "@xmldom/xmldom";
const parser = new TTMLParser({ domParser: new DOMParser(),});
const generator = new TTMLGenerator({ domImplementation: new DOMImplementation(), xmlSerializer: new XMLSerializer(),});Static methods are not suitable for Node.js.
Function Mode
Section titled “Function Mode”Import parseTTML and exportTTML directly.
import { parseTTML, exportTTML } from "@applemusic-like-lyrics/ttml";
const amllObject = parseTTML("Some TTML string...");const ttmlString = exportTTML(amllObject);The parse result type is AmllLyricResult, which can be directly used in AMLL core.
Internally, this mode calls static methods of TTMLParser/TTMLGenerator. For parsing, it additionally calls toAmllLyrics. So this mode is also not suitable for Node.js.