| import os |
| import gradio as gr |
| from TTS.api import TTS |
|
|
| |
| os.environ["COQUI_TOS_AGREED"] = "1" |
|
|
| |
| tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2") |
|
|
| |
| available_voices = tts.list_speakers() |
| available_languages = tts.list_languages() |
|
|
| def generate_speech(text, voice, language): |
| |
| output_path = "output.wav" |
| tts.tts_to_file(text=text, speaker_wav=voice, language=language, file_path=output_path) |
| return output_path |
|
|
| |
| 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) |