Skip to content

fix(irodori_tts): normalize input text like Python normalize_text - #1164

Merged
0xShug0 merged 2 commits into
0xShug0:mainfrom
KKTTSPJ:pr/irodori-text-normalization
Nov 2, 2026
Merged

0xShug0 merged 2 commits into
0xShug0:mainfrom
KKTTSPJ:pr/irodori-text-normalization

Conversation

@KKTTSPJ

@KKTTSPJ KKTTSPJ commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Summary

irodori_tts normalizes input text with a port of Python Irodori-TTS's normalize_text, but only its literal replacements were ported. The regex rules, strip_outer_brackets and NFKC were missing, so text with common Japanese characters reached the tokenizer differently from Python: half-width katakana, full-width Latin letters and digits, wave dashes (〜 / ~), dash-like characters, and brackets around the whole line. The tokenizers have no normalizer of their own (v4 Small's tokenizer.json has normalizer: null), so this is the only place where it can happen.

This PR completes the port in Python's order:

  1. literal replacements (unchanged)
  2. REGEX_REPLACE_MAP: drop ;▼♀♂《》≪≫①②③④⑤⑥ and the dash-like characters (U+02D7, U+2010–2015, U+2043, U+2212, U+23AF, U+23E4, U+2500, U+2501, U+2E3A, U+2E3B), map ~ / 〜 to ー, collapse three or more … to ……
  3. strip_outer_brackets: remove 「」 『』 () 【】 () that enclose the whole text
  4. NFKC, with the vendored utf8proc (as omnivoice, plapre and fish_drama3 do); irodori_tts now links utf8proc_vendor
  5. ... and .. to … (unchanged)
  6. strip() with Python's whitespace set, instead of space / CR / LF only

Invalid UTF-8 input is now rejected as an invalid request at this step.

Validation

Python reference: Aratako/Irodori-TTS 89f9d8f (irodori_tts/text_normalization.py is the same on its current main).

Normalized text (30 sentences covering each rule: half-width katakana with dakuten, full-width Latin and digits, 〜 / ~, every dash and symbol in the regex, ellipsis runs of 2 to 5, each bracket pair, nested and partial brackets, ?!♥●◯〇, tab / [n] / full-width space, leading and trailing ASCII, NBSP and full-width spaces, compatibility characters like ㍻㌔㈱Ⅰ㎝, emoji and surrogate-pair kanji):

Identical to Python normalize_text(text).strip()
main 11 of 30
This PR 30 of 30

Text without these characters is unchanged. main and this PR give byte-identical WAVs on CUDA for v4 Small, v4.1 Small, 500M v3 and 600M v3 VoiceDesign (no reference, reference audio, and caption where supported; 11 cases).

Audio for affected sentences (v4 Small Q8_0, CUDA, no reference, seed 42, 40 steps; log-mel frame cosine against Python fp32):

Sentence main This PR
「カタカナで書いた〜、テストの文章です。」 0.8156 (3.88 s vs 4.80 s) 0.9997 (same length)
ABC社の新製品は1230円〜です。 0.8585 0.8818
えーと~、それは――つまり、その…………そういうこと。 0.8874 (8.16 s vs 6.72 s) 0.9989 (same length)

For the second sentence, the normalized text and the token ids now match Python exactly. The remaining difference comes from Q8_0: the F16 package gives 0.9997 with this PR.

The same gap showed up while validating #1163 (v4 Large), whose Gemma tokenizer turned two of twelve test sentences into different token ids. This PR is independent of #1163; the two touch different files.

🤖 Generated with Claude Code

audio.cpp applied only the literal replacements of Python Irodori-TTS's
normalize_text. The rest was missing, so text with these characters
reached the tokenizer differently from Python:

- REGEX_REPLACE_MAP: drop `;▼♀♂《》≪≫①-⑥` and dash-like characters
  (U+02D7, U+2010-2015, U+2043, U+2212, U+23AF, U+23E4, U+2500, U+2501,
  U+2E3A, U+2E3B), map `~` / `〜` to `ー`, collapse 3+ `…` to `……`
- strip_outer_brackets: remove 「」『』()【】() that enclose the whole text
- NFKC (utf8proc, already vendored): half-width katakana, full-width Latin
  letters and digits, compatibility characters
- strip(): Python whitespace, not only space / CR / LF

The steps run in Python's order. Text without these characters is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@0xShug0

0xShug0 commented Nov 2, 2026

Copy link
Copy Markdown
Owner

@KKTTSPJ One minor omission: upstream removes U+E63E (), but the PR retains it.

  • Input: こんにちは。今日は晴れです。
  • Expected: こんにちは。今日は晴れです。
  • PR: leaves  in the text

Python's first REGEX_REPLACE_MAP class holds U+E63E, a private-use
character between the double angle brackets and the circled digits that
renders as nothing, and the port missed it. Checked against every code
point: the 32 characters the Python classes match are now exactly the
ones this function drops or maps.

Also keep session.cpp ASCII (the ellipsis comment).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@KKTTSPJ

KKTTSPJ commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, you're right: Python's first class has U+E63E between ≫ and ①, and I missed it because it renders as nothing. Fixed in b995322.

To make sure nothing else is hidden, I tested every code point against Python's REGEX_REPLACE_MAP classes: they match 32 characters, and those are now exactly the ones the C++ function drops or maps. I added your example and a sentence with all 32 characters to the comparison set:

Identical to Python normalize_text(text).strip()
Previous commit 30 of 32 (your example and the 32-character sentence differ)
b995322 32 of 32

The commit also replaces the … in a comment so session.cpp stays ASCII as before.

@0xShug0
0xShug0 merged commit 0f2b66a into 0xShug0:main Nov 2, 2026
7 checks passed
@0xShug0

0xShug0 commented Nov 2, 2026

Copy link
Copy Markdown
Owner

@KKTTSPJ Thanks for the quick turnaround! PR merged.

@KKTTSPJ
KKTTSPJ deleted the pr/irodori-text-normalization branch November 2, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants