36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
"""Qwen3-TTS CustomVoice 冒烟测试:预置音色 + 情感指令生成中文对白。"""
|
|
import os
|
|
import time
|
|
|
|
os.environ.setdefault("HF_HOME", "/home/xsl/SoundGame/models/hf")
|
|
os.environ.setdefault("HF_ENDPOINT", "https://hf-mirror.com")
|
|
|
|
import torch
|
|
import soundfile as sf
|
|
from qwen_tts import Qwen3TTSModel
|
|
|
|
t0 = time.time()
|
|
model = Qwen3TTSModel.from_pretrained(
|
|
"Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice",
|
|
device_map="cuda:0",
|
|
dtype=torch.bfloat16,
|
|
# 未安装 flash-attn,使用默认注意力实现
|
|
)
|
|
print(f"model loaded in {time.time() - t0:.1f}s")
|
|
print("speakers:", model.get_supported_speakers())
|
|
print("languages:", model.get_supported_languages())
|
|
|
|
wavs, sr = model.generate_custom_voice(
|
|
text="快躲开!它来了!",
|
|
language="Chinese",
|
|
speaker="Vivian",
|
|
instruct="用惊恐、急促的语气大声喊出来",
|
|
)
|
|
|
|
out = "/home/xsl/SoundGame/tools/samples/tts_test.wav"
|
|
os.makedirs(os.path.dirname(out), exist_ok=True)
|
|
sf.write(out, wavs[0], sr)
|
|
dur = len(wavs[0]) / sr
|
|
print(f"saved: {out} sr={sr} duration={dur:.2f}s samples={len(wavs[0])}")
|
|
assert dur > 0.3, "audio too short, something went wrong"
|