Skip to content

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.
Terminal window
npm install @applemusic-like-lyrics/lyric

Supported formats in the Lyric package:

FormatExtensionParseStringify
TTML.ttmlparseTTMLstringifyTTML
LRC.lrcparseLrcstringifyLrc
LRC A2.lrc, .alrcparseLrcA2stringifyLrcA2
NetEase YRC.yrcparseYrcstringifyYrc
QQ QRC.qrcparseQrcstringifyQrc
EsLyric.lrc, .eslrcparseEslrcstringifyEslrc
ASS subtitle.assNot supportedstringifyAss
Lyricify Lines.lylparseLylstringifyLyl
Lyricify Syllable.lysparseLysstringifyLys
Lyricify Quick Export.lqeparseLqestringifyLqe

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.

Terminal window
npm install @applemusic-like-lyrics/ttml

The TTML package provides TTML parsing and serialization. For format details, see TTML Format.

It supports two usage modes: class mode and function 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.

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.