SOTA-Class TTS at Compact Scale
Python
Normalize inference text before tokenization
linux295650-ux7f1017325346
diff --git a/audio8_tts_data.py b/audio8_tts_data.pyindex 0c924f1..068286d 100644--- a/audio8_tts_data.py+++ b/audio8_tts_data.py@@ -5,6 +5,7 @@ from __future__ import annotationsimport jsonimport osimport re+import unicodedatafrom collections.abc import Iterable, Iterator, Sequencefrom pathlib import Pathfrom typing import Any@@ -14,14 +15,17 @@ import soundfile as sfimport torchimport torch.nn.functional as F-NUM_CODEBOOKS = 10CODEBOOK_SIZE = 4096def clean_text(value: Any, *, field_name: str = "text") -> str:- """Normalize whitespace while preserving the text's language and punctuation."""- text = " ".join(str(value).strip().split())+ """Remove non-linguistic controls and normalize whitespace for inference."""+ text = "".join(+ " " if char.isspace() else "" if unicodedata.category(char).startswith("C") else char+ for char in str(value)+ )+ text = " ".join(text.split())if not text:raise ValueError(f"{field_name} must not be empty")return textdiff --git a/onnx_runtime/arktts_runtime/prompt.py b/onnx_runtime/arktts_runtime/prompt.pyindex da4eed0..bad1590 100644--- a/onnx_runtime/arktts_runtime/prompt.py+++ b/onnx_runtime/arktts_runtime/prompt.py@@ -1,6 +1,7 @@from __future__ import annotationsimport re+import unicodedatafrom pathlib import Pathimport numpy as np@@ -8,7 +9,11 @@ from tokenizers import Tokenizerdef clean_text(text: str) -> str:- return " ".join(str(text).strip().split())+ value = "".join(+ " " if char.isspace() else "" if unicodedata.category(char).startswith("C") else char+ for char in str(text)+ )+ return " ".join(value.split())def format_reference_text(text: str) -> str:diff --git a/sglang_omni/adapter/sglang_omni/models/audio8_tts/tokenizer.py b/sglang_omni/adapter/sglang_omni/models/audio8_tts/tokenizer.pyindex be786ab..e0d5277 100644--- a/sglang_omni/adapter/sglang_omni/models/audio8_tts/tokenizer.py+++ b/sglang_omni/adapter/sglang_omni/models/audio8_tts/tokenizer.py@@ -3,6 +3,7 @@ from __future__ import annotationsimport inspectimport re+import unicodedatafrom dataclasses import dataclassfrom typing import Any@@ -37,7 +38,11 @@ class Audio8TokenizerAdapter:@staticmethoddef _clean(text: str) -> str:- return " ".join(str(text).strip().split())+ value = "".join(+ " " if char.isspace() else "" if unicodedata.category(char).startswith("C") else char+ for char in str(text)+ )+ return " ".join(value.split())@classmethoddef _reference_text(cls, text: str) -> str: