|
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() |
|
|