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()