parse_lyrics
parse_lyrics(
text: str,
hyphen: str = '-',
primary: str | None = "'",
secondary: str | None = ',',
)Turns typed lyrics into LyricSyllables, one per syllable, in order.
Whitespace separates words and hyphen separates syllables; each word goes through Word.from_string, so the stress marks work the same way (primary=None turns them off). A token ending in the hyphen continues into the next token, so “Al- le- lu- ia” and a line-wrapped “Al--lu-ia” both spell one word.
>>> syllables = parse_lyrics("Al-le-'lu-ia, sing to 'Je-sus")
>>> syllables
[LyricSyllable('Al -'), LyricSyllable('- le -'), LyricSyllable('- lu -'), LyricSyllable('- ia,'), LyricSyllable('sing'), LyricSyllable('to'), LyricSyllable('Je -'), LyricSyllable('- sus')]
>>> [s.text for s in syllables if s.lexical_stress is LexicalStress.PRIMARY]
['lu', 'Je']
>>> syllables[0].word is syllables[3].word
True
>>> [str(s) for s in parse_lyrics("Al- le-\nlu- ia")]
['Al -', '- le -', '- lu -', '- ia']
>>> parse_lyrics("")
[]