返回模型
说明文档
Supertonic 量化 INT8 — 离线 TTS (Shadow0482)
本仓库包含 Supertonic 文本转语音流水线的 INT8 优化 ONNX 模型。这些模型是官方 Supertonic 模型的量化版本,专为离线、低延迟、CPU 友好的推理而设计。
FP16 版本仅用于实验,但声码器目前在 Div 节点中存在类型不匹配(float32 vs float16),因此 FP16 推理不稳定。
因此,INT8 是实际离线使用的推荐格式。
🚀 特性
✔ 100% 离线执行
无需网络。使用 ONNX Runtime 直接加载 ONNX 模型。
✔ 完整 Supertonic 推理栈
- 文本编码器 (Text Encoder)
- 时长预测器 (Duration Predictor)
- 向量估计器 (Vector Estimator)
- 声码器
✔ INT8 动态量化
- 大幅减小模型体积
- CPU 友好的推理
- 极低的内存占用
- 兼容 ONNX Runtime CPUExecutionProvider
✔ 相同的音频质量文本输出
在 CPU 上速度大幅提升的同时,仍能生成清晰可懂的语音。
📦 仓库结构
int8_dynamic/
duration_predictor.int8.onnx
text_encoder.int8.onnx
vector_estimator.int8.onnx
vocoder.int8.onnx
fp16/
(包含实验性 FP16 模型 — 声码器目前不稳定)
仅 INT8 目录 保证稳定。
🔊 基准测试中使用的测试句子
Greetings! You are listening to your newly quantized model.
I have been squished, squeezed, compressed, minimized, optimized,
digitized, and lightly traumatized to save disk space.
The testing framework automatically verifies my integrity,
measures how much weight I lost,
and checks if I can still talk without glitching into a robot dolphin.
If you can hear this clearly, the quantization ritual was a complete success.
📈 基准测试摘要 (CPU)
| 模型 | 精度 | 时间 (秒) | 输出 | 状态 |
|---|---|---|---|---|
| INT8 动态量化 | int8 | 变化范围:约 3.0–7.0 秒 | *.wav |
✅ 正常 |
| FP32 (基线) | float32 | 慢约 2–4 倍 | *.wav |
✅ 正常 |
| FP16 | 混合 | ❌ 失败 | — | 🚫 无法加载声码器 |
🖥️ 离线推理指南
以下是运行完全离线 INT8 推理的简洁 Python 脚本。
🧩 依赖要求
pip install onnxruntime numpy soundfile
📜 offline_tts_int8.py
import onnxruntime as ort
import numpy as np
import json
import soundfile as sf
from pathlib import Path
# ---------------------------------------------------------
# 1) 配置
# ---------------------------------------------------------
MODEL_DIR = Path("int8_dynamic") # 包含 *.int8.onnx 的文件夹
VOICE_STYLE = "assets/voice_styles/M1.json"
text_encoder_path = MODEL_DIR / "text_encoder.int8.onnx"
duration_pred_path = MODEL_DIR / "duration_predictor.int8.onnx"
vector_estimator_path = MODEL_DIR / "vector_estimator.int8.onnx"
vocoder_path = MODEL_DIR / "vocoder.int8.onnx"
TEST_TEXT = (
"Hello! This is the INT8 offline version of Supertonic speaking. "
"Everything you hear right now is running fully offline."
)
# ---------------------------------------------------------
# 2) 加载分词器
# ---------------------------------------------------------
unicode_path = Path("assets/onnx/unicode_indexer.json")
tokenizer = json.load(open(unicode_path))
def encode_text(text: str):
ids = []
for ch in text:
if ch in tokenizer["token2idx"]:
ids.append(tokenizer["token2idx"][ch])
else:
ids.append(tokenizer["token2idx"]["<unk>"])
return np.array([ids], dtype=np.int64)
# ---------------------------------------------------------
# 3) 加载模型 (CPU)
# ---------------------------------------------------------
def load_session(model_path):
return ort.InferenceSession(
str(model_path),
providers=["CPUExecutionProvider"]
)
sess_text = load_session(text_encoder_path)
sess_dur = load_session(duration_pred_path)
sess_vec = load_session(vector_estimator_path)
sess_voc = load_session(vocoder_path)
# ---------------------------------------------------------
# 4) 运行文本编码器
# ---------------------------------------------------------
text_ids = encode_text(TEST_TEXT)
text_mask = np.ones((1, 1, text_ids.shape[1]), dtype=np.float32)
style_ttl = np.zeros((1, 50, 256), dtype=np.float32)
text_out = sess_text.run(
None,
{
"text_ids": text_ids,
"text_mask": text_mask,
"style_ttl": style_ttl
}
)[0]
# ---------------------------------------------------------
# 5) 运行时长预测器
# ---------------------------------------------------------
style_dp = np.zeros((1, 8, 16), dtype=np.float32)
dur_out = sess_dur.run(
None,
{
"text_ids": text_ids,
"text_mask": text_mask,
"style_dp": style_dp
}
)[0]
durations = np.maximum(dur_out.astype(int), 1)
# ---------------------------------------------------------
# 6) 向量估计器
# ---------------------------------------------------------
latent = sess_vec.run(None, {"latent": text_out})[0]
# ---------------------------------------------------------
# 7) 声码器 → WAV
# ---------------------------------------------------------
wav = sess_voc.run(None, {"latent": latent})[0][0]
sf.write("output_int8.wav", wav, 24000)
print("Saved: output_int8.wav")
🎧 输出
运行后:
python offline_tts_int8.py
您将获得:
output_int8.wav
可在任何系统上离线播放。
📝 注意事项
- 仅 INT8 模型稳定且被推荐使用。
- FP16 声码器目前由于
Div节点中的类型不匹配而失败。 - INT8 推理不需要互联网连接。
- 这些模型非常适合嵌入式或低配置机器。
📄 许可证
模型遵循 Supertone 的许可条款。 量化版本遵循相同的许可条款。
Shadow0482/supertonic-quantized
作者 Shadow0482
text-to-speech
↓ 0
♥ 2
创建时间: 2025-11-23 11:53:58+00:00
更新时间: 2025-11-23 13:31:05+00:00
在 Hugging Face 上查看文件 (10)
.gitattributes
README.md
fp16/duration_predictor.fp16.onnx
ONNX
fp16/text_encoder.fp16.onnx
ONNX
fp16/vector_estimator.fp16.onnx
ONNX
fp16/vocoder.fp16.onnx
ONNX
int8_dynamic/duration_predictor.int8.onnx
ONNX
int8_dynamic/text_encoder.int8.onnx
ONNX
int8_dynamic/vector_estimator.int8.onnx
ONNX
int8_dynamic/vocoder.int8.onnx
ONNX