Spaces:
Paused
Paused
Create app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940import gradio as grfrom TTS.api import TTS
# Load YourTTS / XTTS v2 model from Hugging Facemodel_name = "tts_models/multilingual/multi-dataset/xtts_v2"tts = TTS(model_name)
def generate_speech(text, emotion, ref_audio=None): output_path = "output.wav" # If a reference voice is provided, use it for cloning if ref_audio: tts.tts_to_file( text=text, file_path=output_path, speaker_wav=ref_audio, emotion=emotion ) else: tts.tts_to_file( text=text, file_path=output_path, emotion=emotion ) return output_path
iface = gr.Interface( fn=generate_speech, inputs=[ gr.Textbox(label="Text to Speak"), gr.Dropdown(choices=["neutral", "happy", "sad", "angry"], label="Emotion"), gr.Audio(source="upload", type="filepath", label="Reference Voice (optional)") ], outputs=gr.Audio(type="filepath"), title="Voice Cloning with Emotions", description="Upload a short voice sample, type text, pick emotion → Get speech in that cloned voice.")
iface.launch()app.pyAdded+40