File size: 1,297 Bytes
5b910d3 ec3f74a c5d2b90 5b910d3 ec3f74a 5b910d3 ec3f74a 5b910d3 ec3f74a 5b910d3 ec3f74a 5b910d3 ec3f74a 5b910d3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
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) |