|
import tempfile |
|
|
|
import gradio as gr |
|
|
|
from neon_tts_plugin_coqui import CoquiTTS |
|
|
|
|
|
LANGUAGES = list(CoquiTTS.langs.keys()) |
|
default_lang = "en" |
|
|
|
|
|
|
|
title = "ChatGPTBots.net | TTS" |
|
description = "A deep learning toolkit for Text-to-Speech, battle-tested in research and production" |
|
info = "More info at [TTS](https://chatgptbots.net)" |
|
|
|
|
|
coquiTTS = CoquiTTS() |
|
|
|
|
|
def tts(text: str, language: str): |
|
print(text, language) |
|
|
|
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp: |
|
coquiTTS.get_tts(text, fp, speaker = {"language" : language}) |
|
return fp.name |
|
|
|
|
|
|
|
with gr.Blocks() as blocks: |
|
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>" |
|
+ title |
|
+ "</h1>") |
|
gr.Markdown(description) |
|
with gr.Row(): |
|
with gr.Column(): |
|
textbox = gr.Textbox( |
|
label="Input", |
|
value=CoquiTTS.langs[default_lang]["sentence"], |
|
max_lines=3, |
|
) |
|
radio = gr.Radio( |
|
label="Language", |
|
choices=LANGUAGES, |
|
value=default_lang |
|
) |
|
with gr.Row(): |
|
submit = gr.Button("Submit", variant="primary") |
|
audio = gr.Audio(label="Output", interactive=False) |
|
gr.Markdown(info) |
|
gr.Markdown("<center>" |
|
+f'<img src={badge} alt="visitors badge"/>' |
|
+"</center>") |
|
|
|
|
|
submit.click( |
|
tts, |
|
[textbox, radio], |
|
[audio], |
|
) |
|
radio.change(lambda lang: CoquiTTS.langs[lang]["sentence"], radio, textbox) |
|
|
|
|
|
|
|
blocks.launch() |