File size: 1,987 Bytes
7c206f9
 
 
 
 
 
 
7a2c904
 
 
 
 
 
f8e168f
 
7a2c904
 
b28fa4b
 
 
dcb73c4
b28fa4b
 
 
7c206f9
 
 
 
 
 
 
 
 
 
 
 
b28fa4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dcb73c4
 
 
b28fa4b
 
 
 
 
 
 
7a2c904
 
b28fa4b
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import tempfile

import gradio as gr

from neon_tts_plugin_coqui import CoquiTTS


language_phrases = {
    "en": "Hello, how are you?",
    "pl": "Witam, jak się masz?",
    "uk": "Привіт, як твої справи?",
}

LANGUAGES = list(language_phrases.keys())



title = "🐸💬 - NeonAI Coqui AI TTS Plugin"
description = "🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production"
info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
badge = "https://visitor-badge-reloaded.herokuapp.com/badge?page_id=neongeckocom.neon-tts-plugin-coqui"



coquiTTS = CoquiTTS()


def tts(text: str, language: str):
    print(text, language)
    # return output
    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():# equal_height=False
        with gr.Column():# variant="panel"
            textbox = gr.Textbox(
                label="Input",
                value="Hello, how are you?",
                max_lines=3,
            )
            radio = gr.Radio(
                label="Language",
                choices=LANGUAGES,
            )
            with gr.Row():# mobile_collapse=False
                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>")

    # actions
    submit.click(
        tts,
        [textbox, radio],
        [audio],
    )
    radio.change(lambda lang: language_phrases[lang], radio, textbox)



blocks.launch()