TTML Processor
A high-performance Rust library for parsing and generating TTML files, specifically tailored for the Apple Music and AMLL formats.
A Note on Specialization
This library is not a general-purpose TTML subtitle parser. It is specifically designed to handle the unique conventions, metadata structures, and extensions (e.g., itunes:* attributes, <iTunesMetadata>) found in TTML files used by Apple Music. Attempting to use it on generic TTML subtitle files may result in errors or incomplete data.
Usage
Add ttml_processor to your Cargo.toml:
[]
= "0.4.0" # Replace with the latest version
Parsing Example
use parse_ttml;
Generation Example
use ;
Generator Options
GeneratorConfig controls the shape of the generated TTML:
use_apple_format_rules— write per-line translations/transliterations into<head>and follow Apple Music's background-vocal conventions. Whenfalse, per-line translations/transliterations are emitted as inlinex-translation/x-romanspans instead. Word-by-word translations/transliterations always go into<head>.format— pretty-print the XML instead of emitting it as a single line.line_timing— generate line-by-line lyrics:itunes:timing="Line", plain text inside each<p>with no per-syllable<span>, word-by-word translations/transliterations flattened to line text (their placement still followsuse_apple_format_rules), and background vocals omitted.
[!NOTE]
line_timingis the only way to produce line-by-line TTML. Setting thetiming_modemetadata to"Line"merely writes that value into theitunes:timingattribute, the per-syllable<span>s are still emitted. Callers usually decide whether to enableline_timingeither by checking that every main lyric line has at most one syllable, or — when the input comes from a trustworthy source — by reading the parsedTTMLMetadata.timing_modeor another high-confidence timing-mode signal.
License
This project is licensed under the MIT License. See the LICENSE file for details.