Spaces:
Running
Running
alessandro trinca tornidor
commited on
Commit
·
a9078f6
1
Parent(s):
baf2993
feat: rename some gradio components, fix some grammar typos
Browse files- aip_trainer/lambdas/app_description.md +2 -2
- app.py +36 -35
aip_trainer/lambdas/app_description.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
# AI Pronunciation Trainer
|
| 2 |
|
| 3 |
-
See [my fork](https://github.com/trincadev/ai-pronunciation-trainer) of [AI Pronunciation Trainer](https://github.com/Thiagohgl/ai-pronunciation-trainer)
|
| 4 |
for more details.
|
| 5 |
|
| 6 |
-
Selecting a new example invalidates all previous inputs (Text-to-Speech audio and Speech-to-Text recordings): in that case you should recorder again your audio
|
| 7 |
|
| 8 |
Right now this tool uses {sample_rate_start} as sample rate value. From empirical tests the best sample rate value is 48000.
|
|
|
|
| 1 |
# AI Pronunciation Trainer
|
| 2 |
|
| 3 |
+
See [my fork](https://github.com/trincadev/ai-pronunciation-trainer) of [AI Pronunciation Trainer](https://github.com/Thiagohgl/ai-pronunciation-trainer) repository
|
| 4 |
for more details.
|
| 5 |
|
| 6 |
+
Selecting a new example invalidates all previous inputs (Text-to-Speech audio and Speech-to-Text recordings): in that case you should recorder again your audio speech.
|
| 7 |
|
| 8 |
Right now this tool uses {sample_rate_start} as sample rate value. From empirical tests the best sample rate value is 48000.
|
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import json
|
| 2 |
from pathlib import Path
|
| 3 |
import gradio as gr
|
| 4 |
|
|
@@ -19,15 +18,15 @@ with gr.Blocks() as gradio_app:
|
|
| 19 |
|
| 20 |
project_root_folder = Path(PROJECT_ROOT_FOLDER)
|
| 21 |
with open(project_root_folder / "aip_trainer" / "lambdas" / "app_description.md", "r", encoding="utf-8") as app_description_src:
|
| 22 |
-
|
| 23 |
-
gr.Markdown(
|
| 24 |
with gr.Row():
|
| 25 |
with gr.Column(scale=4, min_width=300):
|
| 26 |
with gr.Row():
|
| 27 |
with gr.Column(scale=2, min_width=80):
|
| 28 |
-
|
| 29 |
with gr.Column(scale=5, min_width=160):
|
| 30 |
-
|
| 31 |
label="Difficulty",
|
| 32 |
value=0,
|
| 33 |
choices=[
|
|
@@ -41,7 +40,7 @@ with gr.Blocks() as gradio_app:
|
|
| 41 |
btn_random_phrase = gr.Button(value="Choose a random phrase")
|
| 42 |
with gr.Row():
|
| 43 |
with gr.Column(scale=7, min_width=300):
|
| 44 |
-
|
| 45 |
lines=3,
|
| 46 |
label="Learner Transcription",
|
| 47 |
value="Hi there, how are you?",
|
|
@@ -61,29 +60,31 @@ with gr.Blocks() as gradio_app:
|
|
| 61 |
show_download_button=True,
|
| 62 |
)
|
| 63 |
with gr.Column(scale=4, min_width=320):
|
| 64 |
-
|
| 65 |
lines=2, placeholder=None, label="Transcripted text", visible=False
|
| 66 |
)
|
| 67 |
-
|
| 68 |
lines=1,
|
| 69 |
placeholder=None,
|
| 70 |
label="Letters correctness",
|
| 71 |
visible=False,
|
| 72 |
)
|
| 73 |
with gr.Row():
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
| 81 |
lines=1, placeholder=None, label="Learner phonetic transcription"
|
| 82 |
)
|
| 83 |
-
|
| 84 |
lines=1, placeholder=None, label="Ideal phonetic transcription"
|
| 85 |
)
|
| 86 |
-
|
| 87 |
html_output = gr.HTML(
|
| 88 |
label="Speech accuracy output",
|
| 89 |
elem_id="speech-output",
|
|
@@ -105,18 +106,18 @@ with gr.Blocks() as gradio_app:
|
|
| 105 |
["Die König-Ludwig-Eiche ist ein Naturdenkmal im Staatsbad Brückenau, einem Ortsteil des drei Kilometer nordöstlich gelegenen Bad Brückenau im Landkreis Bad Kissingen in Bayern.", "de", 3],
|
| 106 |
["Some machine learning models are designed to understand and generate human-like text based on the input they receive.", "en", 3],
|
| 107 |
],
|
| 108 |
-
inputs=[
|
| 109 |
)
|
| 110 |
|
| 111 |
def get_updated_score_by_language(text: str, audio_rec: str | Path, lang: str, score_de: float, score_en: float):
|
| 112 |
_transcripted_text, _letter_correctness, _pronunciation_accuracy, _recording_ipa, _ideal_ipa, _res = lambdaSpeechToScore.get_speech_to_score_tuple(text, audio_rec, lang)
|
| 113 |
output = {
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
}
|
| 121 |
match lang:
|
| 122 |
case "de":
|
|
@@ -136,26 +137,26 @@ with gr.Blocks() as gradio_app:
|
|
| 136 |
|
| 137 |
btn.click(
|
| 138 |
get_updated_score_by_language,
|
| 139 |
-
inputs=[
|
| 140 |
outputs=[
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
number_score_de, number_score_en
|
| 148 |
],
|
| 149 |
)
|
| 150 |
btn_run_tts.click(
|
| 151 |
fn=lambdaTTS.get_tts,
|
| 152 |
-
inputs=[
|
| 153 |
outputs=audio_tts,
|
| 154 |
)
|
| 155 |
btn_random_phrase.click(
|
| 156 |
lambdaGetSample.get_random_selection,
|
| 157 |
-
inputs=[
|
| 158 |
-
outputs=[
|
| 159 |
)
|
| 160 |
btn_random_phrase.click(
|
| 161 |
clear2,
|
|
@@ -164,7 +165,7 @@ with gr.Blocks() as gradio_app:
|
|
| 164 |
)
|
| 165 |
html_output.change(
|
| 166 |
None,
|
| 167 |
-
inputs=[
|
| 168 |
outputs=[html_output],
|
| 169 |
js=js.js_update_ipa_output,
|
| 170 |
)
|
|
|
|
|
|
|
| 1 |
from pathlib import Path
|
| 2 |
import gradio as gr
|
| 3 |
|
|
|
|
| 18 |
|
| 19 |
project_root_folder = Path(PROJECT_ROOT_FOLDER)
|
| 20 |
with open(project_root_folder / "aip_trainer" / "lambdas" / "app_description.md", "r", encoding="utf-8") as app_description_src:
|
| 21 |
+
md_app_description = app_description_src.read()
|
| 22 |
+
gr.Markdown(md_app_description.format(sample_rate_start=sample_rate_start))
|
| 23 |
with gr.Row():
|
| 24 |
with gr.Column(scale=4, min_width=300):
|
| 25 |
with gr.Row():
|
| 26 |
with gr.Column(scale=2, min_width=80):
|
| 27 |
+
radio_language = gr.Radio(["de", "en"], label="Language", value="en")
|
| 28 |
with gr.Column(scale=5, min_width=160):
|
| 29 |
+
radio_difficulty = gr.Radio(
|
| 30 |
label="Difficulty",
|
| 31 |
value=0,
|
| 32 |
choices=[
|
|
|
|
| 40 |
btn_random_phrase = gr.Button(value="Choose a random phrase")
|
| 41 |
with gr.Row():
|
| 42 |
with gr.Column(scale=7, min_width=300):
|
| 43 |
+
text_learner_transcription = gr.Textbox(
|
| 44 |
lines=3,
|
| 45 |
label="Learner Transcription",
|
| 46 |
value="Hi there, how are you?",
|
|
|
|
| 60 |
show_download_button=True,
|
| 61 |
)
|
| 62 |
with gr.Column(scale=4, min_width=320):
|
| 63 |
+
text_transcripted_hidden = gr.Textbox(
|
| 64 |
lines=2, placeholder=None, label="Transcripted text", visible=False
|
| 65 |
)
|
| 66 |
+
text_letter_correctness = gr.Textbox(
|
| 67 |
lines=1,
|
| 68 |
placeholder=None,
|
| 69 |
label="Letters correctness",
|
| 70 |
visible=False,
|
| 71 |
)
|
| 72 |
with gr.Row():
|
| 73 |
+
gr.Markdown("Speech accuracy score (%)")
|
| 74 |
+
with gr.Row():
|
| 75 |
+
with gr.Column(min_width=100):
|
| 76 |
+
number_pronunciation_accuracy = gr.Number(label="Current score")
|
| 77 |
+
with gr.Column(min_width=100):
|
| 78 |
+
number_score_de = gr.Number(label="Global score DE", value=0)
|
| 79 |
+
with gr.Column(min_width=100):
|
| 80 |
+
number_score_en = gr.Number(label="Global score EN", value=0)
|
| 81 |
+
text_recording_ipa = gr.Textbox(
|
| 82 |
lines=1, placeholder=None, label="Learner phonetic transcription"
|
| 83 |
)
|
| 84 |
+
text_ideal_ipa = gr.Textbox(
|
| 85 |
lines=1, placeholder=None, label="Ideal phonetic transcription"
|
| 86 |
)
|
| 87 |
+
text_raw_json_output_hidden = gr.Textbox(lines=1, placeholder=None, label="text_raw_json_output_hidden", visible=False)
|
| 88 |
html_output = gr.HTML(
|
| 89 |
label="Speech accuracy output",
|
| 90 |
elem_id="speech-output",
|
|
|
|
| 106 |
["Die König-Ludwig-Eiche ist ein Naturdenkmal im Staatsbad Brückenau, einem Ortsteil des drei Kilometer nordöstlich gelegenen Bad Brückenau im Landkreis Bad Kissingen in Bayern.", "de", 3],
|
| 107 |
["Some machine learning models are designed to understand and generate human-like text based on the input they receive.", "en", 3],
|
| 108 |
],
|
| 109 |
+
inputs=[text_learner_transcription, radio_language, radio_difficulty],
|
| 110 |
)
|
| 111 |
|
| 112 |
def get_updated_score_by_language(text: str, audio_rec: str | Path, lang: str, score_de: float, score_en: float):
|
| 113 |
_transcripted_text, _letter_correctness, _pronunciation_accuracy, _recording_ipa, _ideal_ipa, _res = lambdaSpeechToScore.get_speech_to_score_tuple(text, audio_rec, lang)
|
| 114 |
output = {
|
| 115 |
+
text_transcripted_hidden: _transcripted_text,
|
| 116 |
+
text_letter_correctness: _letter_correctness,
|
| 117 |
+
number_pronunciation_accuracy: _pronunciation_accuracy,
|
| 118 |
+
text_recording_ipa: _recording_ipa,
|
| 119 |
+
text_ideal_ipa: _ideal_ipa,
|
| 120 |
+
text_raw_json_output_hidden: _res,
|
| 121 |
}
|
| 122 |
match lang:
|
| 123 |
case "de":
|
|
|
|
| 137 |
|
| 138 |
btn.click(
|
| 139 |
get_updated_score_by_language,
|
| 140 |
+
inputs=[text_learner_transcription, audio_learner_recording_stt, radio_language, number_score_de, number_score_en],
|
| 141 |
outputs=[
|
| 142 |
+
text_transcripted_hidden,
|
| 143 |
+
text_letter_correctness,
|
| 144 |
+
number_pronunciation_accuracy,
|
| 145 |
+
text_recording_ipa,
|
| 146 |
+
text_ideal_ipa,
|
| 147 |
+
text_raw_json_output_hidden,
|
| 148 |
number_score_de, number_score_en
|
| 149 |
],
|
| 150 |
)
|
| 151 |
btn_run_tts.click(
|
| 152 |
fn=lambdaTTS.get_tts,
|
| 153 |
+
inputs=[text_learner_transcription, radio_language],
|
| 154 |
outputs=audio_tts,
|
| 155 |
)
|
| 156 |
btn_random_phrase.click(
|
| 157 |
lambdaGetSample.get_random_selection,
|
| 158 |
+
inputs=[radio_language, radio_difficulty],
|
| 159 |
+
outputs=[text_learner_transcription],
|
| 160 |
)
|
| 161 |
btn_random_phrase.click(
|
| 162 |
clear2,
|
|
|
|
| 165 |
)
|
| 166 |
html_output.change(
|
| 167 |
None,
|
| 168 |
+
inputs=[text_transcripted_hidden, text_letter_correctness],
|
| 169 |
outputs=[html_output],
|
| 170 |
js=js.js_update_ipa_output,
|
| 171 |
)
|