File size: 1,724 Bytes
6f930dd
7979b2a
 
 
6f930dd
7979b2a
aa8293f
7979b2a
 
 
 
 
 
aa8293f
 
 
 
7979b2a
 
aa8293f
 
7979b2a
 
 
 
 
 
 
 
 
abc155e
aa8293f
abc155e
aa8293f
 
 
7979b2a
aa8293f
c8fdd3c
 
 
cbc76d0
c8fdd3c
7979b2a
 
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
from pygoruut.pygoruut import Pygoruut, PygoruutLanguages
import gradio as gr

pygoruut = Pygoruut()
languages = PygoruutLanguages()

def dephon_offline(txt, language_tag, is_reverse, is_punct):
    try:
        response = pygoruut.phonemize(language=language_tag, sentence=txt, is_reverse=is_reverse)
    except TypeError:
        return ''
    if not response or not response.Words:
        return ''
    if is_punct:
        phonetic_line = str(response)
    else:
        phonetic_line = " ".join(word.Phonetic for word in response.Words)
    return phonetic_line

def phonemize(sentence, language, is_reverse, is_punct):
    return dephon_offline(sentence, language, is_reverse, is_punct)

with gr.Blocks() as demo:
    gr.Markdown('''
    # Pygoruut Phonemizer Demo
    This demo allows you to phonemize text using the Pygoruut phonemizer.
    You can specify the language and choose whether to perform reverse phonemization.
    ''')
    with gr.Row():
        sentence = gr.Textbox(label="Sentence", placeholder="Enter the text to phonemize...")
    with gr.Row():
        language = gr.Textbox(label="Language", placeholder="Enter the language tag (e.g., 'en' for English), separate multiple languages by comma (,)...")
    with gr.Row():
        is_reverse = gr.Checkbox(label="Reverse Phonemization")
        is_punct = gr.Checkbox(label="Keep Punctuation")
        submit_btn = gr.Button("Phonemize")
    output = gr.Textbox(label="Phonemized Text")
    submit_btn.click(fn=phonemize, inputs=[sentence, language, is_reverse, is_punct], outputs=output)
    gr.Markdown('''
    # Supported languages
    ''')
    for lang in languages.get_all_supported_languages():
        gr.Markdown('- ' + lang)

demo.launch()