File size: 3,409 Bytes
7f0cc16
 
9b231ac
53016e3
9b231ac
7f0cc16
9b231ac
7f0cc16
9b231ac
53016e3
9b231ac
f64d86f
c594ce9
c3646e2
 
c594ce9
7f0cc16
2c3e79f
f47653c
cd62b9b
53016e3
23ce701
7f0cc16
9b231ac
 
7f0cc16
adc69be
 
 
 
4c93ec9
7f0cc16
9b231ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import gradio as gr
import os
from AinaTheme import AinaGradioTheme
from espeak_phonemizer import Phonemizer
from dotenv import load_dotenv

load_dotenv()

MAX_INPUT_TEXT_LEN = int(os.environ.get("MAX_INPUT_TEXT_LEN", default=325))

#fonemitzador = Phonemizer("ca")

def phonemiser(text, dialect):
    dialects = {"Central": "ca", "Valencian": "ca-va", "North-West": "ca-nw"}
    dialect = dialects[dialect] #Define dialect from espeak-ng-data/lang/roa/ca*
    fonemitzador = Phonemizer(dialect) #Set correct dialect for the phonemiser

    # synthesize

    fonemes = fonemitzador.phonemize(text, keep_clause_breakers=True)

    return fonemes


title = "Comparativa de síntesi lliure en català️"
description="""
Transcripció fonètica en català
Transcipció fonètica per a diferents dialectes del català mitjançant eSpeak.
Phonetic transcription for different dialects of Catalan 
using eSpeak.
repo: https://github.com/projecte-aina/espeak-ng/tree/dev-ca 
"""

def submit_input(input_, dialect):
    output = None
    if input_ is not None and len(input_) < MAX_INPUT_TEXT_LEN:
        output = phonemiser(input_, dialect)
    else:
        gr.Warning(f"Your text exceeds the {MAX_INPUT_TEXT_LEN}-character limit.")
    return output

def change_interactive(text):
    input_state = text
    if input_state.strip() != "":
        return gr.update(interactive = True)
    else:
        return gr.update(interactive = False)
def clean(): 
    return (
        None, 
        None,
    )



with gr.Blocks(**AinaGradioTheme().get_kwargs()) as app:
        
        gr.Markdown(f"<h1 style='text-align: center; margin-bottom: 1rem'>{title}</h1>")

        gr.Markdown(description)

        with gr.Row(equal_height=False):
    
            with gr.Column(variant='panel'):
                input_ = gr.Textbox(
                    label="Text",
                    value="Les coses importants són les que no ho semblen.",
                    lines=4
                )

                dialect = gr.Dropdown(label="Dialect", choices=["Central", "Valencian", "North-West"], value="Central")
                with gr.Row():
                    clear_btn = gr.Button(
                        "Clean", 
                    )
                    submit_btn = gr.Button(
                        "Submit", 
                        variant="primary", 
                    )
            with gr.Column(variant='panel'):
                output = gr.Textbox( 
                    label="Output", 
                    interactive=False, 
                    show_copy_button=True
                )
        gr.Examples(
            label="Examples",
            examples=[
                ["Les coses importants són les que no ho semblen.", "Central"],
                ["Les coses importants són les que no ho semblen.", "Valencian",],
                ["Les coses importants són les que no ho semblen.", "North-West",],
            ],
            inputs=[input_, dialect],
            outputs=output,
            fn=submit_input)

        for button in [submit_btn, clear_btn]:
            input_.change(fn=change_interactive, inputs=[input_], outputs=button)

        clear_btn.click(fn=clean, inputs=[], outputs=[input_, output] , queue=False)
        submit_btn.click(fn=submit_input, inputs=[input_, dialect], outputs=output)
        
app.queue(concurrency_count=2, api_open=False)
app.launch(show_api=False)