File size: 580 Bytes
8aa105f
19b52d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8aa105f
 
19b52d8
8aa105f
19b52d8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

# 加载一个 Hugging Face 预训练的 TTS 模型
tts = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech", device=0)

def tts_inference(text):
    # 使用 TTS 模型生成语音
    audio = tts(text)[0]['audio']
    return audio

# 创建 Gradio 接口
iface = gr.Interface(
    fn=tts_inference, 
    inputs="text", 
    outputs="audio", 
    title="TTS Demo", 
    description="Enter some text and listen to the generated speech."
)

# 启动 Gradio 应用
if __name__ == "__main__":
    iface.launch()