Files
VoiceStudio/tests/test_normalization_inline_preservation.py
T
Rudy Celekli 485e359910 fix(pronunciation): preserve supported pronunciation markup during normalization
The pronunciation layer accepts [[label|replacement]] overrides up to 256
characters, including newlines, but the normalization pre-pass only
protected bracket spans up to 128 characters on one line. A longer valid
override was normalized like ordinary text (numbers inside it were spelled
out), which changed or broke the replacement. Protect the full accepted
grammar.
2026-11-04 22:07:51 -05:00

28 lines
1.0 KiB
Python

"""Accepted pronunciation markup survives the real normalization pre-pass."""
import pytest
@pytest.mark.parametrize("content", [
"label|" + "word " * 26 + "5",
"label|" + "x" * 248 + " 5",
"label|" + "word " * 26 + "\n5",
])
def test_supported_inline_override_preserves_explicit_replacement(content):
from services.pronunciation import apply_pronunciation
from services.text_normalization import normalize_for_tts
assert 128 < len(content) <= 256
markup = "[[" + content + "]]"
# The native Malayalam verbalizer needs no optional num2words import.
raw = markup + " 5"
normalized = normalize_for_tts(raw, "Malayalam")
assert normalized == markup + " അഞ്ച്"
assert apply_pronunciation(normalized) == content.partition("|")[2] + " അഞ്ച്"
def test_long_single_bracket_metadata_remains_opaque():
from services.text_normalization import normalize_text
marker = "[voice:" + "name " * 52 + "5]"
assert normalize_text(marker + " 5", "Malayalam") == marker + " അഞ്ച്"