Skip to content

IndexTTS2 tokenizer needs CJK pre-tokenization for Mandarin input #453

Description

@jc119-chao

Summary

The current IndexTTS2Tokenizer normalization handles Latin text, but continuous Mandarin input can remain in the form ▁你好.... With the published aufklarer/IndexTTS2-MLX-fp16 bundle, this can leave no valid SentencePiece path and produce IndexTTS2TokenizerError.unencodableText.

I encountered this while integrating the existing speech-swift IndexTTS2 runtime into a desktop dubbing pipeline. Applying CJK character pre-tokenization allowed real Mandarin synthesis to complete successfully.

Environment

  • speech-swift: 7984666dd7dc9233132c57a09bd9bf490a2ae448
  • model: aufklarer/IndexTTS2-MLX-fp16
  • model revision: 208b3d6ea53a119f3501b3bfd8e666b9b5e8c705
  • Apple M2, 24 GB RAM
  • macOS 26.5
  • Swift 6.3.2

Current behavior

normalizedPieceText(for:) currently:

  1. applies compatibility normalization;
  2. collapses whitespace;
  3. uppercases the full string;
  4. inserts only at whitespace boundaries.

For Mandarin without spaces, multiple CJK scalars therefore remain one continuous segment. This does not mirror the upstream IndexTTS2 text front end, which pre-tokenizes CJK characters before BPE lookup.

Example input:

你好,这是一个中文合成测试。

The model-compatible pre-tokenized shape is approximately:

▁你▁好▁,▁这▁是▁一▁个▁中▁文▁合▁成▁测▁试▁.

Local fix evaluated

The local integration currently applies:

  • per-scalar CJK pre-tokenization;
  • IndexTTS2-compatible punctuation normalization;
  • locale-aware number expansion;
  • an unknown-token fallback so one unsupported scalar does not invalidate the entire path.

This was enough to run real Mandarin synthesis through the Swift/MLX runtime and a persistent JSONL bridge. The surrounding desktop integration has 22 runtime checks, but the tokenizer change itself still needs focused speech-swift regression tests before a PR.

Proposed upstream scope

If this approach matches the intended text front end, I can prepare a focused PR containing only:

  1. the tokenizer normalization fix;
  2. regression tests for Mandarin, mixed Chinese/English, punctuation, numbers, and unknown scalars;
  3. no application-specific bridge or dependency pinning.

Would you prefer the PR to mirror the upstream Python normalizer closely, or keep the Swift implementation limited to the minimum CJK boundary fix?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions