File size: 807 Bytes
3d7c149 a18e4de 74822ae 3d7c149 e3146d0 3d7c149 74822ae 3d7c149 a18e4de 74822ae 3d7c149 74822ae e3146d0 74822ae e3146d0 74822ae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import os
import gradio as gr
from TTS.api import TTS
import torch
import numpy as np
os.environ['COQUI_TOS_AGREED'] = '1'
device = "cuda" if torch.cuda.is_available() else "cpu"
# 初始化 TTS 模型
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
# 定义语音合成函数
def text_to_speech(text):
# 将文本转换为语音
#wav = tts.tts(text)
# 保存为临时文件
wav_file = "output.wav"
wav = tts.tts(text, language = "zh-cn", speaker_wav = "E_sample.wav")
return wav, tts.sample_rate
# 创建 Gradio 接口
iface = gr.Interface(
fn=text_to_speech,
inputs=gr.Textbox(lines=2, placeholder="输入文本..."),
outputs=gr.Audio(type="numpy"),
title=f"测试",
description=f"当前device: {device}"
)
# 启动接口
iface.launch() |