Spaces:
Running
Running
alessandro trinca tornidor
commited on
Commit
·
ca7e6be
1
Parent(s):
0931910
feat: add global score component by language
Browse files- aip_trainer/lambdas/lambdaSpeechToScore.py +2 -2
- app.py +35 -5
aip_trainer/lambdas/lambdaSpeechToScore.py
CHANGED
@@ -126,12 +126,12 @@ def get_speech_to_score_dict(real_text: str, file_bytes_or_audiotmpfile: str | d
|
|
126 |
duration = time.time() - start
|
127 |
duration_tot = time.time() - start0
|
128 |
app_logger.info(f'Time to post-process results: {duration}, tot_duration:{duration_tot}.')
|
129 |
-
pronunciation_accuracy =
|
130 |
ipa_transcript = result['recording_ipa']
|
131 |
|
132 |
return {'real_transcript': result['recording_transcript'],
|
133 |
'ipa_transcript': ipa_transcript,
|
134 |
-
'pronunciation_accuracy': pronunciation_accuracy,
|
135 |
'real_transcripts': real_transcripts, 'matched_transcripts': matched_transcripts,
|
136 |
'real_transcripts_ipa': real_transcripts_ipa, 'matched_transcripts_ipa': matched_transcripts_ipa,
|
137 |
'pair_accuracy_category': pair_accuracy_category,
|
|
|
126 |
duration = time.time() - start
|
127 |
duration_tot = time.time() - start0
|
128 |
app_logger.info(f'Time to post-process results: {duration}, tot_duration:{duration_tot}.')
|
129 |
+
pronunciation_accuracy = float(result['pronunciation_accuracy'])
|
130 |
ipa_transcript = result['recording_ipa']
|
131 |
|
132 |
return {'real_transcript': result['recording_transcript'],
|
133 |
'ipa_transcript': ipa_transcript,
|
134 |
+
'pronunciation_accuracy': float(f"{pronunciation_accuracy:.2f}"),
|
135 |
'real_transcripts': real_transcripts, 'matched_transcripts': matched_transcripts,
|
136 |
'real_transcripts_ipa': real_transcripts_ipa, 'matched_transcripts_ipa': matched_transcripts_ipa,
|
137 |
'pair_accuracy_category': pair_accuracy_category,
|
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from pathlib import Path
|
2 |
import gradio as gr
|
3 |
|
@@ -20,6 +21,9 @@ with gr.Blocks() as gradio_app:
|
|
20 |
with open(project_root_folder / "aip_trainer" / "lambdas" / "app_description.md", "r", encoding="utf-8") as app_description_src:
|
21 |
app_description = app_description_src.read()
|
22 |
gr.Markdown(app_description)
|
|
|
|
|
|
|
23 |
with gr.Row():
|
24 |
with gr.Column(scale=4, min_width=300):
|
25 |
with gr.Row():
|
@@ -81,9 +85,7 @@ with gr.Blocks() as gradio_app:
|
|
81 |
label="Letters correctness",
|
82 |
visible=False,
|
83 |
)
|
84 |
-
pronunciation_accuracy = gr.
|
85 |
-
lines=1, placeholder=None, label="Pronunciation accuracy %"
|
86 |
-
)
|
87 |
recording_ipa = gr.Textbox(
|
88 |
lines=1, placeholder=None, label="Learner phonetic transcription"
|
89 |
)
|
@@ -102,9 +104,36 @@ with gr.Blocks() as gradio_app:
|
|
102 |
)
|
103 |
with gr.Row():
|
104 |
btn = gr.Button(value="Recognize speech accuracy")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
btn.click(
|
106 |
-
|
107 |
-
inputs=[learner_transcription, audio_learner_recording_stt, language],
|
108 |
outputs=[
|
109 |
transcripted_text,
|
110 |
letter_correctness,
|
@@ -112,6 +141,7 @@ with gr.Blocks() as gradio_app:
|
|
112 |
recording_ipa,
|
113 |
ideal_ipa,
|
114 |
res,
|
|
|
115 |
],
|
116 |
)
|
117 |
btn_run_tts.click(
|
|
|
1 |
+
import json
|
2 |
from pathlib import Path
|
3 |
import gradio as gr
|
4 |
|
|
|
21 |
with open(project_root_folder / "aip_trainer" / "lambdas" / "app_description.md", "r", encoding="utf-8") as app_description_src:
|
22 |
app_description = app_description_src.read()
|
23 |
gr.Markdown(app_description)
|
24 |
+
with gr.Row():
|
25 |
+
number_score_de = gr.Number(label="Score DE", value=0.0)
|
26 |
+
number_score_en = gr.Number(label="Score EN", value=0.0)
|
27 |
with gr.Row():
|
28 |
with gr.Column(scale=4, min_width=300):
|
29 |
with gr.Row():
|
|
|
85 |
label="Letters correctness",
|
86 |
visible=False,
|
87 |
)
|
88 |
+
pronunciation_accuracy = gr.Number(label="Pronunciation accuracy %")
|
|
|
|
|
89 |
recording_ipa = gr.Textbox(
|
90 |
lines=1, placeholder=None, label="Learner phonetic transcription"
|
91 |
)
|
|
|
104 |
)
|
105 |
with gr.Row():
|
106 |
btn = gr.Button(value="Recognize speech accuracy")
|
107 |
+
|
108 |
+
def get_updated_score_by_language(text: str, audio_rec: str | Path, lang: str, score_de: float, score_en: float):
|
109 |
+
_transcripted_text, _letter_correctness, _pronunciation_accuracy, _recording_ipa, _ideal_ipa, _res = lambdaSpeechToScore.get_speech_to_score_tuple(text, audio_rec, lang)
|
110 |
+
output = {
|
111 |
+
transcripted_text: _transcripted_text,
|
112 |
+
letter_correctness: _letter_correctness,
|
113 |
+
pronunciation_accuracy: _pronunciation_accuracy,
|
114 |
+
recording_ipa: _recording_ipa,
|
115 |
+
ideal_ipa: _ideal_ipa,
|
116 |
+
res: _res,
|
117 |
+
}
|
118 |
+
match lang:
|
119 |
+
case "de":
|
120 |
+
return {
|
121 |
+
number_score_de: float(score_de) + float(_pronunciation_accuracy),
|
122 |
+
number_score_en: float(score_en),
|
123 |
+
**output
|
124 |
+
}
|
125 |
+
case "en":
|
126 |
+
return {
|
127 |
+
number_score_en: float(score_en) + float(_pronunciation_accuracy),
|
128 |
+
number_score_de: float(score_de),
|
129 |
+
**output
|
130 |
+
}
|
131 |
+
case _:
|
132 |
+
raise NotImplementedError(f"Language {lang} not supported")
|
133 |
+
|
134 |
btn.click(
|
135 |
+
get_updated_score_by_language,
|
136 |
+
inputs=[learner_transcription, audio_learner_recording_stt, language, number_score_de, number_score_en],
|
137 |
outputs=[
|
138 |
transcripted_text,
|
139 |
letter_correctness,
|
|
|
141 |
recording_ipa,
|
142 |
ideal_ipa,
|
143 |
res,
|
144 |
+
number_score_de, number_score_en
|
145 |
],
|
146 |
)
|
147 |
btn_run_tts.click(
|