This commit is contained in:
parent
54cb82f1b9
commit
581d8f8f47
|
|
@ -0,0 +1,36 @@
|
||||||
|
from TTS.api import TTS
|
||||||
|
|
||||||
|
# 检查是否有可用的 GPU
|
||||||
|
import torch
|
||||||
|
use_gpu = torch.cuda.is_available()
|
||||||
|
device = "cuda" if use_gpu else "cpu"
|
||||||
|
|
||||||
|
print(f"🎯 设备选择: {device}")
|
||||||
|
|
||||||
|
# **加载 XTTS v2,指定使用 GPU**
|
||||||
|
print("🚀 正在加载 XTTS v2 模型,请稍候...")
|
||||||
|
tts_xtts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
|
||||||
|
tts_xtts.to("cuda") # 改为显式指定 GPU
|
||||||
|
|
||||||
|
# **使用 XTTS v2 生成语音**
|
||||||
|
tts_xtts.tts_to_file(
|
||||||
|
text="记者从越秀区了解到,广州博物馆隆重推出“吉祥有年——广州博物馆藏吉祥文物展”...",
|
||||||
|
file_path="output_xtts_gpu.wav",
|
||||||
|
speaker_wav="example_speaker_en.wav", # 参考音频
|
||||||
|
language="zh-cn",
|
||||||
|
split_sentences=True
|
||||||
|
)
|
||||||
|
print("✅ XTTS v2 语音合成完成!已保存到 output_xtts_gpu.wav 🎵")
|
||||||
|
|
||||||
|
# **加载 VITS**
|
||||||
|
print("🚀 正在加载 VITS 模型,请稍候...")
|
||||||
|
tts_vits = TTS("tts_models/en/ljspeech/vits", gpu=use_gpu)
|
||||||
|
|
||||||
|
# **使用 VITS 生成语音**
|
||||||
|
tts_vits.tts_to_file(
|
||||||
|
text="This is a high-quality text-to-speech conversion using XTTS v2 and VITS.",
|
||||||
|
split_sentences=True,
|
||||||
|
file_path="output_vits_gpu.wav"
|
||||||
|
)
|
||||||
|
print("✅ VITS 语音合成完成!已保存到 output_vits_gpu.wav 🎵")
|
||||||
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue