Skip to content

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.py
index 0c924f1..068286d 100644
--- a/audio8_tts_data.py
+++ b/audio8_tts_data.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import json
import os
import re
+import unicodedata
from collections.abc import Iterable, Iterator, Sequence
from pathlib import Path
from typing import Any
@@ -14,14 +15,17 @@ import soundfile as sf
import torch
import torch.nn.functional as F
-
NUM_CODEBOOKS = 10
CODEBOOK_SIZE = 4096
def 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 text
diff --git a/onnx_runtime/arktts_runtime/prompt.py b/onnx_runtime/arktts_runtime/prompt.py
index da4eed0..bad1590 100644
--- a/onnx_runtime/arktts_runtime/prompt.py
+++ b/onnx_runtime/arktts_runtime/prompt.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import re
+import unicodedata
from pathlib import Path
import numpy as np
@@ -8,7 +9,11 @@ from tokenizers import Tokenizer
def 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.py
index 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 annotations
import inspect
import re
+import unicodedata
from dataclasses import dataclass
from typing import Any
@@ -37,7 +38,11 @@ class Audio8TokenizerAdapter:
@staticmethod
def _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())
@classmethod
def _reference_text(cls, text: str) -> str: