XTTS / app.py
azils3's picture
Update app.py
5b910d3 verified
raw
history blame contribute delete
No virus
1.3 kB
import os
import gradio as gr
from TTS.api import TTS
# Set the environment variable to agree to the terms of service
os.environ["COQUI_TOS_AGREED"] = "1"
# Initialize the TTS model
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
# Get available voices and languages
available_voices = tts.list_speakers()
available_languages = tts.list_languages()
def generate_speech(text, voice, language):
# Generate speech
output_path = "output.wav"
tts.tts_to_file(text=text, speaker_wav=voice, language=language, file_path=output_path)
return output_path
# Create Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# XTTS v2 Text-to-Speech Generator")
with gr.Row():
text_input = gr.Textbox(label="Input Text", placeholder="Enter text to be synthesized")
with gr.Row():
voice_dropdown = gr.Dropdown(label="Select Voice", choices=available_voices)
language_dropdown = gr.Dropdown(label="Select Language", choices=available_languages)
with gr.Row():
generate_button = gr.Button("Generate Speech")
with gr.Row():
audio_output = gr.Audio(label="Generated Speech")
generate_button.click(generate_speech, inputs=[text_input, voice_dropdown, language_dropdown], outputs=audio_output)
demo.launch(debug=True)