Skip to content

fix(ssml): spell_out splits combining marks and regional-indicator pairs #2825

Open

Description

@RerankerGuo

Summary

backend/services/ssml_lite.py:spell_out iterates by Python str codepoints, so a single visible character built from a base plus one or more combining marks (NFD-decomposed) is split into multiple space-separated units. The same happens to paired regional-indicator sequences (flag emoji), even though the JS-side SSML-LITE path was already fixed by 55f3d58 fix(ssml): spell out by grapheme.

Repro

import unicodedata
from services.ssml_lite import spell_out

# NFD: 'é' = e + U+0301
print(spell_out(unicodedata.normalize('NFD', 'café')))
# c a f e  ́   (the combining acute stands alone; TTS will drop it)

# regional indicators: '🇺🇸' = U+1F1FA U+1F1F8
print(spell_out('🇺🇸'))
# 🇺 🇸          (a single character announced as two)

The correct output is the same as the composed / precomposed form (c a f é, 🇺🇸). The same bug does not exist for NFC text because precomposed characters are a single codepoint, but the function is reachable from longform_parser.py for any audiobook / longform line that originated in a Mac keyboard buffer or an editor that emits NFD (Pages, TextEdit, Vim with decompose on, copy-paste from a web page).

Suggested fix

Segment by grapheme cluster using only stdlib: NFC-normalize first (handles decomposed Latin/Hangul), then group trailing unicodedata.combining(c) characters onto the previous base. The narrow fix covers the common audiobook cases without adding a new dependency. Regional-indicator / ZWJ emoji remain a separate, smaller follow-up (a real grapheme library would be the right tool, and would also have to land in the locked deps).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions