File size: 554 Bytes
292e9ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from transformers import pipeline
import gradio as gr
import tempfile

# Load TTS pipeline with a model that works in Spaces
tts = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech")

def greet(name):
    greeting = f"Hello {name}!! You're amazing!"
    audio_data = tts(greeting)["audio"]

    # Save to a temp WAV file
    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
        f.write(audio_data)
        return f.name

demo = gr.Interface(fn=greet, inputs="text", outputs=gr.Audio(type="filepath"))
demo.launch()