|
import gradio as gr |
|
import random |
|
|
|
|
|
|
|
short_texts = [ |
|
"سالام", "رەھمەت", "ياخشىمۇسىز" |
|
] |
|
long_texts = [ |
|
"مەكتەپكە بارغاندا تېخىمۇ بىلىملىك بولۇپ قېلىمەن.", |
|
"يېزا مەنزىرىسى ھەقىقەتەن گۈزەل.", |
|
"پېقىرلارغا ياردەم قىلىش مەنەم پەرزەندە." |
|
] |
|
|
|
|
|
def generate_text(type, script_choice): |
|
"""Generate a random Uyghur short or long text based on type.""" |
|
from umsc import UgMultiScriptConverter |
|
ug_arab_to_latn = UgMultiScriptConverter('UAS', 'ULS') |
|
if type == "short": |
|
if script_choice == "Uyghur Arabic": |
|
return random.choice(short_texts) |
|
else: |
|
return ug_arab_to_latn(random.choice(short_texts)) |
|
elif type == "long": |
|
if script_choice == "Uyghur Arabic": |
|
return random.choice(long_texts) |
|
else: |
|
return ug_arab_to_latn(random.choice(long_texts)) |
|
|
|
def generate_example_pronunciation(input_text, script): |
|
|
|
example_audio = None |
|
return example_audio |
|
|
|
def check_pronunciation(input_text, script, user_audio): |
|
|
|
transcript_ugArab_box = "Automatic transcription of your audio (Arabic)..." |
|
transcript_ugLatn_box = "Automatic transcription of your audio (Latin)..." |
|
correct_pronunciation = "Correct pronunciation in IPA" |
|
user_pronunciation = "User pronunciation in IPA" |
|
pronunciation_match = "Matching segments in green, mismatched in red" |
|
pronunciation_score = 85.7 |
|
return transcript_ugArab_box, transcript_ugLatn_box, correct_pronunciation, user_pronunciation, pronunciation_match, pronunciation_score |
|
|
|
with gr.Blocks() as app: |
|
with gr.Row(): |
|
|
|
with gr.Column(scale=1): |
|
with gr.Row(): |
|
script_choice = gr.Dropdown( |
|
choices=["Uyghur Arabic", "Uyghur Latin"], |
|
label="1. Select Input Script", |
|
value="Uyghur Arabic", |
|
interactive=True |
|
) |
|
with gr.Row(): |
|
input_text = gr.Textbox( |
|
label="2. Input Uyghur Text to Pronounce or Generate Text with Buttons below", |
|
placeholder="Enter Uyghur text here...", |
|
) |
|
|
|
with gr.Row(): |
|
generate_short_btn = gr.Button("Generate Short Text") |
|
generate_long_btn = gr.Button("Generate Long Text") |
|
with gr.Row(): |
|
example_audio = gr.Audio(label="3. Click \"Generate Example Pronunciation\"") |
|
with gr.Row(): |
|
tts_btn = gr.Button("Generate Example Pronunciation") |
|
with gr.Row(): |
|
user_audio = gr.Audio( |
|
label="4. Record/Upload Your Pronunciation", |
|
sources=["microphone", "upload"], |
|
type="filepath", |
|
) |
|
with gr.Row(): |
|
check_btn = gr.Button("Check My Pronunciation") |
|
|
|
|
|
with gr.Column(scale=1): |
|
|
|
with gr.Group(): |
|
with gr.Row(): |
|
transcript_ugArab_box = gr.Textbox( |
|
label="Transcript (Uyghur Arabic)", |
|
placeholder="ASR transcription of your audio..." |
|
) |
|
with gr.Row(): |
|
transcript_ugLatn_box = gr.Textbox( |
|
label="Transcript (Uyghur Latin)", |
|
placeholder="ASR transcription of your audio..." |
|
) |
|
|
|
|
|
with gr.Group(): |
|
with gr.Row(): |
|
correct_pronunciation_box = gr.Textbox( |
|
label="Correct Pronunciation", |
|
placeholder="IPA representation of the correct pronunciation..." |
|
) |
|
with gr.Row(): |
|
user_pronunciation_box = gr.Textbox( |
|
label="User Pronunciation", |
|
placeholder="IPA representation of your pronunciation..." |
|
) |
|
|
|
with gr.Group(): |
|
with gr.Row(): |
|
match_box = gr.Textbox( |
|
label="Phonetic Match", |
|
placeholder="Matching and mismatched characters visualized here..." |
|
) |
|
with gr.Row(): |
|
score_box = gr.Textbox( |
|
label="Phonetic Score", |
|
placeholder="Your pronunciation score as a percentage..." |
|
) |
|
|
|
|
|
generate_short_btn.click( |
|
generate_text, |
|
inputs=["short", script_choice], |
|
outputs=input_text |
|
) |
|
|
|
generate_long_btn.click( |
|
generate_text, |
|
inputs=["long", script_choice], |
|
outputs=input_text |
|
) |
|
|
|
tts_btn.click( |
|
generate_example_pronunciation, |
|
inputs=[input_text, script_choice], |
|
outputs=[example_audio] |
|
) |
|
|
|
check_btn.click( |
|
check_pronunciation, |
|
inputs=[input_text, script_choice, user_audio], |
|
outputs=[transcript_ugArab_box, transcript_ugLatn_box, correct_pronunciation_box, user_pronunciation_box, match_box, score_box] |
|
) |
|
|
|
if __name__ == "__main__": |
|
app.launch() |