Spaces:
Running
Running
alessandro trinca tornidor
commited on
Commit
·
1985a38
1
Parent(s):
1d0bb75
test: refactor test_lambdaSpeechToScore.py to test all fields
Browse files
aip_trainer/lambdas/lambdaSpeechToScore.py
CHANGED
@@ -22,12 +22,13 @@ transform = Resample(orig_freq=sample_rate_start, new_freq=16000)
|
|
22 |
|
23 |
|
24 |
def lambda_handler(event, context):
|
25 |
-
|
|
|
26 |
|
27 |
real_text = data['title']
|
28 |
-
|
29 |
-
app_logger.debug(f"base64Audio:{
|
30 |
-
file_bytes_or_audiotmpfile = base64.b64decode(
|
31 |
language = data['language']
|
32 |
|
33 |
if len(real_text) == 0:
|
|
|
22 |
|
23 |
|
24 |
def lambda_handler(event, context):
|
25 |
+
body = event['body']
|
26 |
+
data = json.loads(body)
|
27 |
|
28 |
real_text = data['title']
|
29 |
+
base64_audio = data["base64Audio"]
|
30 |
+
app_logger.debug(f"base64Audio:{base64_audio} ...")
|
31 |
+
file_bytes_or_audiotmpfile = base64.b64decode(base64_audio[22:].encode('utf-8'))
|
32 |
language = data['language']
|
33 |
|
34 |
if len(real_text) == 0:
|
tests/events/GetAccuracyFromRecordedAudio.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
tests/events/example.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"key": "value",
|
3 |
+
"example": {
|
4 |
+
"body": {
|
5 |
+
"real_transcript": "hi how are you",
|
6 |
+
"ipa_transcript": "ha\u026a ha\u028a \u0259r ju",
|
7 |
+
"pronunciation_accuracy": 69.0,
|
8 |
+
"real_transcripts": "Hi there, how are you?",
|
9 |
+
"matched_transcripts": "hi - how are you",
|
10 |
+
"real_transcripts_ipa": "ha\u026a \u00f0\u025br, ha\u028a \u0259r ju?",
|
11 |
+
"matched_transcripts_ipa": "ha\u026a ha\u028a \u0259r ju",
|
12 |
+
"pair_accuracy_category": "0 2 0 0 0",
|
13 |
+
"start_time": "0.2245625 1.3228125 0.852125 1.04825 1.3228125",
|
14 |
+
"end_time": "0.559875 1.658125 1.14825 1.344375 1.658125",
|
15 |
+
"is_letter_correct_all_words": "11 000001 111 111 1111 "
|
16 |
+
}
|
17 |
+
}
|
18 |
+
}
|
tests/events/get_speech_to_score_dict_en.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"real_transcript": "hi how are you", "ipa_transcript": "ha\u026a ha\u028a \u0259r ju", "pronunciation_accuracy": 69.0, "real_transcripts": "Hi there, how are you?", "matched_transcripts": "hi - how are you", "real_transcripts_ipa": "ha\u026a \u00f0\u025br, ha\u028a \u0259r ju?", "matched_transcripts_ipa": "ha\u026a ha\u028a \u0259r ju", "pair_accuracy_category": "0 2 0 0 0", "start_time": "0.2245625 1.3228125 0.852125 1.04825 1.3228125", "end_time": "0.559875 1.658125 1.14825 1.344375 1.658125", "is_letter_correct_all_words": "11 000001 111 111 1111 "}
|
tests/lambdas/test_lambdaSpeechToScore.py
CHANGED
@@ -9,56 +9,219 @@ from aip_trainer.lambdas import lambdaSpeechToScore
|
|
9 |
from tests import EVENTS_FOLDER
|
10 |
|
11 |
|
12 |
-
text_dict = {
|
13 |
-
|
14 |
-
"
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
}
|
17 |
-
|
18 |
"de": {
|
19 |
-
"
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
"
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
},
|
31 |
"en": {
|
32 |
-
"
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
"pronunciation_accuracy": 69.0,
|
35 |
-
"real_transcripts":
|
36 |
"matched_transcripts": "hi - how are you",
|
37 |
-
"real_transcripts_ipa": "
|
38 |
-
"matched_transcripts_ipa": "
|
39 |
"pair_accuracy_category": "0 2 0 0 0",
|
40 |
"start_time": "0.2245625 1.3228125 0.852125 1.04825 1.3228125",
|
41 |
"end_time": "0.559875 1.658125 1.14825 1.344375 1.658125",
|
42 |
"is_letter_correct_all_words": "11 000001 111 111 1111 ",
|
43 |
},
|
44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
|
|
|
|
|
|
46 |
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
from aip_trainer.lambdas import lambdaSpeechToScore
|
49 |
|
50 |
-
with
|
51 |
try:
|
52 |
lambdaSpeechToScore.get_speech_to_score_dict(
|
53 |
-
real_text,
|
|
|
|
|
|
|
54 |
)
|
55 |
except exc as e:
|
56 |
-
|
57 |
raise e
|
58 |
|
59 |
|
60 |
def check_value_by_field(value, match):
|
61 |
import re
|
|
|
62 |
assert len(value.strip()) > 0
|
63 |
for word in value.lstrip().rstrip().split(" "):
|
64 |
word_check = re.findall(match, word.strip())
|
@@ -73,32 +236,12 @@ def check_output_by_field(output, key, match, expected_output):
|
|
73 |
return output
|
74 |
|
75 |
|
76 |
-
def check_output(
|
77 |
from pathlib import Path
|
78 |
-
|
|
|
79 |
try:
|
80 |
-
|
81 |
-
assert len(output["matched_transcripts_ipa"].strip()) > 0
|
82 |
-
assert len(output["ipa_transcript"].strip()) > 0
|
83 |
-
assert len(output["real_transcripts_ipa"].strip()) > 0
|
84 |
-
output = check_output_by_field(
|
85 |
-
output, "is_letter_correct_all_words", "[01]+", expected_output
|
86 |
-
)
|
87 |
-
match_numbers = "\\d+\\.\\d+"
|
88 |
-
output = check_output_by_field(output, "end_time", match_numbers, expected_output)
|
89 |
-
output = check_output_by_field(
|
90 |
-
output, "start_time", match_numbers, expected_output
|
91 |
-
)
|
92 |
-
pronunciation_accuracy = output["pronunciation_accuracy"]
|
93 |
-
assert isinstance(pronunciation_accuracy, float)
|
94 |
-
assert pronunciation_accuracy <= 100
|
95 |
-
output["matched_transcripts"] = expected_output["matched_transcripts"]
|
96 |
-
output["matched_transcripts_ipa"] = expected_output["matched_transcripts_ipa"]
|
97 |
-
output["pronunciation_accuracy"] = expected_output["pronunciation_accuracy"]
|
98 |
-
output["pair_accuracy_category"] = expected_output["pair_accuracy_category"]
|
99 |
-
output["ipa_transcript"] = expected_output["ipa_transcript"]
|
100 |
-
output["real_transcript"] = expected_output["real_transcript"]
|
101 |
-
output["real_transcripts_ipa"] = expected_output["real_transcripts_ipa"]
|
102 |
if check_audio_files:
|
103 |
audio_files = output["audio_files"]
|
104 |
audio_durations = output["audio_durations"]
|
@@ -110,21 +253,115 @@ def check_output(self, output, expected_output, check_audio_files=False):
|
|
110 |
app_logger.info(f"path_audio_file:{path_audio_file}.")
|
111 |
assert path_audio_file.is_file()
|
112 |
path_audio_file.unlink()
|
113 |
-
|
114 |
-
output["audio_files"] = [*audio_files]
|
115 |
-
expected_output["audio_files"] = [*audio_files]
|
116 |
-
n_durations = len(output["audio_durations"])
|
117 |
-
audio_durations = [x/4 + 0.5 for x in range(n_durations)]
|
118 |
-
output["audio_durations"] = [*audio_durations]
|
119 |
-
expected_output["audio_durations"] = [*audio_durations]
|
120 |
-
app_logger.info(f"output audio_files:{output['audio_files']}.")
|
121 |
-
app_logger.info(f"expected_output audio_files:{expected_output['audio_files']}.")
|
122 |
-
self.assertDictEqual(output, expected_output)
|
123 |
except Exception as e:
|
124 |
app_logger.error(f"e:{e}.")
|
125 |
raise e
|
126 |
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
|
129 |
def setUp(self):
|
130 |
if platform.system() == "Windows" or platform.system() == "Win32":
|
@@ -137,18 +374,19 @@ class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
|
|
137 |
del os.environ["PYTHONUTF8"]
|
138 |
|
139 |
def test_GetAccuracyFromRecordedAudio(self):
|
|
|
140 |
with open(EVENTS_FOLDER / "GetAccuracyFromRecordedAudio.json", "r") as src:
|
141 |
inputs_outputs = json.load(src)
|
142 |
inputs = inputs_outputs["inputs"]
|
143 |
-
|
144 |
-
|
145 |
-
current_expected_output = outputs[event_name]
|
146 |
output = lambdaSpeechToScore.lambda_handler(event_content, [])
|
147 |
output = json.loads(output)
|
|
|
148 |
app_logger.info(
|
149 |
f"output type:{type(output)}, expected_output type:{type(current_expected_output)}."
|
150 |
)
|
151 |
-
|
152 |
|
153 |
def test_lambda_handler_empty_text(self):
|
154 |
from aip_trainer.lambdas import lambdaSpeechToScore
|
@@ -177,233 +415,119 @@ class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
|
|
177 |
)
|
178 |
|
179 |
def test_get_speech_to_score_en_ok(self):
|
180 |
-
|
181 |
-
|
182 |
-
language = "en"
|
183 |
-
path = EVENTS_FOLDER / f"test_{language}.wav"
|
184 |
-
output = lambdaSpeechToScore.get_speech_to_score_dict(
|
185 |
-
real_text=text_dict[language],
|
186 |
-
file_bytes_or_audiotmpfile=str(path),
|
187 |
-
language=language,
|
188 |
-
remove_random_file=False,
|
189 |
-
)
|
190 |
-
check_output(self, output, expected_output[language])
|
191 |
-
|
192 |
-
def test_get_speech_to_score_en_ok_remove_input_file(self):
|
193 |
-
import shutil
|
194 |
-
from aip_trainer.lambdas import lambdaSpeechToScore
|
195 |
-
|
196 |
-
language = "en"
|
197 |
-
path = EVENTS_FOLDER / f"test_{language}.wav"
|
198 |
-
path2 = EVENTS_FOLDER / f"test2_{language}.wav"
|
199 |
-
shutil.copy(path, path2)
|
200 |
-
assert path2.exists() and path2.is_file()
|
201 |
-
output = lambdaSpeechToScore.get_speech_to_score_dict(
|
202 |
-
real_text=text_dict[language],
|
203 |
-
file_bytes_or_audiotmpfile=str(path2),
|
204 |
-
language=language,
|
205 |
-
remove_random_file=True,
|
206 |
-
)
|
207 |
-
assert not path2.exists()
|
208 |
-
check_output(self, output, expected_output[language])
|
209 |
|
210 |
def test_get_speech_to_score_de_ok(self):
|
211 |
-
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
real_text=text_dict[language],
|
217 |
-
file_bytes_or_audiotmpfile=str(path),
|
218 |
-
language=language,
|
219 |
-
remove_random_file=False,
|
220 |
)
|
221 |
-
check_output(self, output, expected_output[language])
|
222 |
|
223 |
def test_get_speech_to_score_de_ok_remove_input_file(self):
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
language = "de"
|
228 |
-
path = EVENTS_FOLDER / f"test_{language}.wav"
|
229 |
-
path2 = EVENTS_FOLDER / f"test2_{language}.wav"
|
230 |
-
shutil.copy(path, path2)
|
231 |
-
assert path2.exists() and path2.is_file()
|
232 |
-
output = lambdaSpeechToScore.get_speech_to_score_dict(
|
233 |
-
real_text=text_dict[language],
|
234 |
-
file_bytes_or_audiotmpfile=str(path2),
|
235 |
-
language=language,
|
236 |
-
remove_random_file=True,
|
237 |
)
|
238 |
-
assert not path2.exists()
|
239 |
-
check_output(self, output, expected_output[language])
|
240 |
|
241 |
def test_get_speech_to_score_tuple_de_ok(self):
|
242 |
-
|
243 |
-
|
244 |
-
language = "de"
|
245 |
-
path = EVENTS_FOLDER / f"test_{language}.wav"
|
246 |
-
(
|
247 |
-
real_transcripts,
|
248 |
-
is_letter_correct_all_words,
|
249 |
-
pronunciation_accuracy,
|
250 |
-
ipa_transcript,
|
251 |
-
real_transcripts_ipa,
|
252 |
-
num_words,
|
253 |
-
first_audio_file,
|
254 |
-
dumped,
|
255 |
-
) = lambdaSpeechToScore.get_speech_to_score_tuple(
|
256 |
-
real_text=text_dict[language],
|
257 |
-
file_bytes_or_audiotmpfile=str(path),
|
258 |
-
language=language,
|
259 |
-
remove_random_file=False,
|
260 |
)
|
261 |
-
assert real_transcripts == text_dict[language]
|
262 |
-
check_value_by_field(is_letter_correct_all_words, "[01]+")
|
263 |
-
assert isinstance(pronunciation_accuracy, float)
|
264 |
-
assert pronunciation_accuracy <= 100
|
265 |
-
assert len(ipa_transcript.strip()) > 0
|
266 |
-
assert len(real_transcripts_ipa.strip()) > 0
|
267 |
-
assert num_words == 6
|
268 |
-
first_audio_file_path = Path(first_audio_file)
|
269 |
-
assert first_audio_file_path.exists() and first_audio_file_path.is_file()
|
270 |
-
json_loaded = json.loads(dumped)
|
271 |
-
check_output(self, json_loaded, expected_output[language], check_audio_files=True)
|
272 |
|
273 |
def test_get_speech_to_score_tuple_en_ok(self):
|
274 |
-
|
275 |
-
|
276 |
-
language = "en"
|
277 |
-
path = EVENTS_FOLDER / f"test_{language}.wav"
|
278 |
-
(
|
279 |
-
real_transcripts,
|
280 |
-
is_letter_correct_all_words,
|
281 |
-
pronunciation_accuracy,
|
282 |
-
ipa_transcript,
|
283 |
-
real_transcripts_ipa,
|
284 |
-
num_words,
|
285 |
-
first_audio_file,
|
286 |
-
dumped,
|
287 |
-
) = lambdaSpeechToScore.get_speech_to_score_tuple(
|
288 |
-
real_text=text_dict[language],
|
289 |
-
file_bytes_or_audiotmpfile=str(path),
|
290 |
-
language=language,
|
291 |
-
remove_random_file=False,
|
292 |
)
|
293 |
-
assert real_transcripts == text_dict[language]
|
294 |
-
check_value_by_field(is_letter_correct_all_words, "[01]+")
|
295 |
-
assert isinstance(pronunciation_accuracy, float)
|
296 |
-
assert pronunciation_accuracy <= 100
|
297 |
-
assert len(ipa_transcript.strip()) > 0
|
298 |
-
assert len(real_transcripts_ipa.strip()) > 0
|
299 |
-
assert num_words == 5
|
300 |
-
first_audio_file_path = Path(first_audio_file)
|
301 |
-
assert first_audio_file_path.exists() and first_audio_file_path.is_file()
|
302 |
-
check_output(self, json.loads(dumped), expected_output[language], check_audio_files=True)
|
303 |
|
304 |
def test_get_speech_to_score_dict__de_empty_input_text(self):
|
305 |
language = "de"
|
306 |
path = EVENTS_FOLDER / f"test_{language}.wav"
|
307 |
-
assert_raises_get_speech_to_score_dict(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
def test_get_speech_to_score_dict__en_empty_input_text(self):
|
310 |
language = "en"
|
311 |
path = EVENTS_FOLDER / f"test_{language}.wav"
|
312 |
-
assert_raises_get_speech_to_score_dict(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
|
314 |
def test_get_speech_to_score_dict__de_empty_input_file(self):
|
315 |
language = "de"
|
316 |
-
assert_raises_get_speech_to_score_dict(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
|
318 |
def test_get_speech_to_score_dict__en_empty_input_file(self):
|
319 |
language = "en"
|
320 |
-
assert_raises_get_speech_to_score_dict(
|
321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
def test_get_speech_to_score_dict__empty_language(self):
|
323 |
-
assert_raises_get_speech_to_score_dict(
|
324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
def test_get_speech_to_score_dict__empty_language(self):
|
326 |
language = "en"
|
327 |
path_file = str(EVENTS_FOLDER / "empty_file.wav")
|
328 |
-
assert_raises_get_speech_to_score_dict(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
329 |
|
330 |
def test_get_selected_word_valid_index_de_ok(self):
|
331 |
-
|
332 |
-
|
333 |
-
input_text = text_dict["de1"]
|
334 |
-
_, _, _, _, _, _, _, output_json = lambdaSpeechToScore.get_speech_to_score_tuple(
|
335 |
-
input_text,
|
336 |
-
str(path), language,
|
337 |
-
False
|
338 |
)
|
339 |
-
idx_recorded_word = 2
|
340 |
-
output_loaded = json.loads(output_json)
|
341 |
-
audio_file, word, duration = lambdaSpeechToScore.get_selected_word(idx_recorded_word, output_json)
|
342 |
-
audio_file_path = Path(audio_file)
|
343 |
-
assert audio_file_path.exists() and audio_file_path.is_file()
|
344 |
-
assert duration > 0
|
345 |
-
words_list = text_dict["de1"].split()
|
346 |
-
assert word == words_list[idx_recorded_word]
|
347 |
-
for file_to_del in output_loaded["audio_files"]:
|
348 |
-
Path(file_to_del).unlink()
|
349 |
|
350 |
def test_get_selected_word_valid_index_en_ok(self):
|
351 |
-
|
352 |
-
|
353 |
-
_, _, _, _, _, _, _, output_json = lambdaSpeechToScore.get_speech_to_score_tuple(
|
354 |
-
text_dict[language],
|
355 |
-
str(path), language,
|
356 |
-
False
|
357 |
)
|
358 |
-
idx_recorded_word = 2
|
359 |
-
output_loaded = json.loads(output_json)
|
360 |
-
audio_file, word, duration = lambdaSpeechToScore.get_selected_word(idx_recorded_word, output_json)
|
361 |
-
audio_file_path = Path(audio_file)
|
362 |
-
assert audio_file_path.exists() and audio_file_path.is_file()
|
363 |
-
assert duration > 0
|
364 |
-
words_list = text_dict[language].split()
|
365 |
-
assert word == words_list[idx_recorded_word]
|
366 |
-
for file_to_del in output_loaded["audio_files"]:
|
367 |
-
Path(file_to_del).unlink()
|
368 |
|
369 |
def test_get_selected_word_invalid_index_de(self):
|
370 |
-
|
371 |
-
path = EVENTS_FOLDER / f"test_{language}_easy.wav"
|
372 |
-
_, _, _, _, _, _, _, output_json = lambdaSpeechToScore.get_speech_to_score_tuple(
|
373 |
-
text_dict["de1"],
|
374 |
-
str(path), language,
|
375 |
-
False
|
376 |
-
)
|
377 |
-
with self.assertRaises(IndexError):
|
378 |
-
try:
|
379 |
-
lambdaSpeechToScore.get_selected_word(120, output_json)
|
380 |
-
except IndexError as ie:
|
381 |
-
msg = str(ie)
|
382 |
-
assert msg == 'list index out of range'
|
383 |
-
raise ie
|
384 |
|
385 |
def test_get_selected_word_invalid_index_en(self):
|
386 |
-
|
387 |
-
path = EVENTS_FOLDER / f"test_{language}_easy.wav"
|
388 |
-
_, _, _, _, _, _, _, output_json = lambdaSpeechToScore.get_speech_to_score_tuple(
|
389 |
-
text_dict[language],
|
390 |
-
str(path), language,
|
391 |
-
False
|
392 |
-
)
|
393 |
-
with self.assertRaises(IndexError):
|
394 |
-
try:
|
395 |
-
lambdaSpeechToScore.get_selected_word(120, output_json)
|
396 |
-
except IndexError as ie:
|
397 |
-
msg = str(ie)
|
398 |
-
assert msg == 'list index out of range'
|
399 |
-
raise ie
|
400 |
|
401 |
def test_get_selected_word_empty_transcripts(self):
|
402 |
-
raw_json_output = json.dumps(
|
403 |
-
"audio_files": [],
|
404 |
-
|
405 |
-
"audio_durations": []
|
406 |
-
})
|
407 |
idx_recorded_word = 0
|
408 |
with self.assertRaises(IndexError):
|
409 |
lambdaSpeechToScore.get_selected_word(idx_recorded_word, raw_json_output)
|
@@ -413,11 +537,9 @@ class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
|
|
413 |
path = str(EVENTS_FOLDER / f"test_{language}.wav")
|
414 |
start_time = [0.0, 1.0, 2.0]
|
415 |
end_time = [1.0, 2.0, 2.5]
|
416 |
-
|
417 |
audio_files, audio_durations = lambdaSpeechToScore.get_splitted_audio_file(
|
418 |
-
audiotmpfile=path,
|
419 |
-
start_time=start_time,
|
420 |
-
end_time=end_time
|
421 |
)
|
422 |
|
423 |
assert len(audio_files) == len(start_time)
|
@@ -437,9 +559,7 @@ class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
|
|
437 |
with self.assertRaises(LibsndfileError):
|
438 |
try:
|
439 |
lambdaSpeechToScore.get_splitted_audio_file(
|
440 |
-
audiotmpfile="",
|
441 |
-
start_time=start_time,
|
442 |
-
end_time=end_time
|
443 |
)
|
444 |
except LibsndfileError as lsfe:
|
445 |
msg = str(lsfe)
|
@@ -457,13 +577,11 @@ class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
|
|
457 |
with self.assertRaises(LibsndfileError):
|
458 |
try:
|
459 |
lambdaSpeechToScore.get_splitted_audio_file(
|
460 |
-
audiotmpfile=str(path),
|
461 |
-
start_time=start_time,
|
462 |
-
end_time=end_time
|
463 |
)
|
464 |
except LibsndfileError as lsfe:
|
465 |
msg = str(lsfe)
|
466 |
-
assert msg ==
|
467 |
raise lsfe
|
468 |
|
469 |
|
|
|
9 |
from tests import EVENTS_FOLDER
|
10 |
|
11 |
|
12 |
+
text_dict = {"de": "Hallo, wie geht es dir?", "en": "Hi there, how are you?"}
|
13 |
+
expected_get_speech_to_score = {
|
14 |
+
"de": {
|
15 |
+
"real_transcript": "ich bin alexwe beste du",
|
16 |
+
"ipa_transcript": "ɪç biːn aːlɛksvɛː bɛstɛː duː",
|
17 |
+
"pronunciation_accuracy": 18.0,
|
18 |
+
"real_transcripts": "Hallo, wie geht es dir?",
|
19 |
+
"matched_transcripts": "ich bin beste - du",
|
20 |
+
"real_transcripts_ipa": "haloː, viː ɡeːt ɛːs diːr?",
|
21 |
+
"matched_transcripts_ipa": "ɪç biːn bəstə - duː",
|
22 |
+
"pair_accuracy_category": "2 2 2 2 2",
|
23 |
+
"start_time": "0.0 0.3075 1.5785625 2.1346875 2.1346875",
|
24 |
+
"end_time": "0.328 0.6458125 2.15525 2.4730625 2.4730625",
|
25 |
+
"is_letter_correct_all_words": "100001 010 0101 00 1001 ",
|
26 |
+
},
|
27 |
+
"en": {
|
28 |
+
"real_transcript": "hi how are you",
|
29 |
+
"ipa_transcript": "haɪ haʊ ər ju",
|
30 |
+
"pronunciation_accuracy": 69.0,
|
31 |
+
"real_transcripts": "Hi there, how are you?",
|
32 |
+
"matched_transcripts": "hi - how are you",
|
33 |
+
"real_transcripts_ipa": "haɪ ðɛr, haʊ ər ju?",
|
34 |
+
"matched_transcripts_ipa": "haɪ haʊ ər ju",
|
35 |
+
"pair_accuracy_category": "0 2 0 0 0",
|
36 |
+
"start_time": "0.2245625 1.3228125 0.852125 1.04825 1.3228125",
|
37 |
+
"end_time": "0.559875 1.658125 1.14825 1.344375 1.658125",
|
38 |
+
"is_letter_correct_all_words": "11 000001 111 111 1111 ",
|
39 |
+
},
|
40 |
}
|
41 |
+
expected_with_audio_files_splitted_list = {
|
42 |
"de": {
|
43 |
+
"audio_files": [
|
44 |
+
f"{EVENTS_FOLDER}/test_de__part0_start0.0_end0.328..wav",
|
45 |
+
f"{EVENTS_FOLDER}/test_de__part1_start0.3075_end0.6458125..wav",
|
46 |
+
f"{EVENTS_FOLDER}/test_de__part2_start1.5785625_end2.15525..wav",
|
47 |
+
f"{EVENTS_FOLDER}/test_de__part3_start2.1346875_end2.4730625..wav",
|
48 |
+
f"{EVENTS_FOLDER}/test_de__part4_start2.1346875_end2.4730625..wav",
|
49 |
+
],
|
50 |
+
"audio_durations": [
|
51 |
+
0.328,
|
52 |
+
0.3383125,
|
53 |
+
0.5766875,
|
54 |
+
0.3383750000000001,
|
55 |
+
0.3383750000000001,
|
56 |
+
],
|
57 |
+
"real_transcript": "ich bin alexwe beste du",
|
58 |
+
"ipa_transcript": "ɪç biːn aːlɛksvɛː bɛstɛː duː",
|
59 |
+
"pronunciation_accuracy": 18.0,
|
60 |
+
"real_transcripts": "Hallo, wie geht es dir?",
|
61 |
+
"matched_transcripts": "ich bin beste - du",
|
62 |
+
"real_transcripts_ipa": "haloː, viː ɡeːt ɛːs diːr?",
|
63 |
+
"matched_transcripts_ipa": "ɪç biːn bəstə - duː",
|
64 |
+
"pair_accuracy_category": "2 2 2 2 2",
|
65 |
+
"start_time": "0.0 0.3075 1.5785625 2.1346875 2.1346875",
|
66 |
+
"end_time": "0.328 0.6458125 2.15525 2.4730625 2.4730625",
|
67 |
+
"is_letter_correct_all_words": "100001 010 0101 00 1001 ",
|
68 |
},
|
69 |
"en": {
|
70 |
+
"audio_files": [
|
71 |
+
f"{EVENTS_FOLDER}/test_en__part0_start0.2245625_end0.559875..wav",
|
72 |
+
f"{EVENTS_FOLDER}/test_en__part1_start1.3228125_end1.658125..wav",
|
73 |
+
f"{EVENTS_FOLDER}/test_en__part2_start0.852125_end1.14825..wav",
|
74 |
+
f"{EVENTS_FOLDER}/test_en__part3_start1.04825_end1.344375..wav",
|
75 |
+
f"{EVENTS_FOLDER}/test_en__part4_start1.3228125_end1.658125..wav",
|
76 |
+
],
|
77 |
+
"audio_durations": [
|
78 |
+
0.3353125,
|
79 |
+
0.3353125000000001,
|
80 |
+
0.29612499999999997,
|
81 |
+
0.2961250000000002,
|
82 |
+
0.3353125000000001,
|
83 |
+
],
|
84 |
+
"real_transcript": "hi how are you",
|
85 |
+
"ipa_transcript": "haɪ haʊ ər ju",
|
86 |
"pronunciation_accuracy": 69.0,
|
87 |
+
"real_transcripts": "Hi there, how are you?",
|
88 |
"matched_transcripts": "hi - how are you",
|
89 |
+
"real_transcripts_ipa": "haɪ ðɛr, haʊ ər ju?",
|
90 |
+
"matched_transcripts_ipa": "haɪ haʊ ��r ju",
|
91 |
"pair_accuracy_category": "0 2 0 0 0",
|
92 |
"start_time": "0.2245625 1.3228125 0.852125 1.04825 1.3228125",
|
93 |
"end_time": "0.559875 1.658125 1.14825 1.344375 1.658125",
|
94 |
"is_letter_correct_all_words": "11 000001 111 111 1111 ",
|
95 |
},
|
96 |
}
|
97 |
+
expected_with_selected_word_valid_index = {
|
98 |
+
"de": {
|
99 |
+
"audio_files": [
|
100 |
+
f"{EVENTS_FOLDER}/test_de_easy__part0_start0.0_end0.4733125..wav",
|
101 |
+
f"{EVENTS_FOLDER}/test_de_easy__part1_start0.3733125_end0.70425..wav",
|
102 |
+
f"{EVENTS_FOLDER}/test_de_easy__part2_start0.60425_end0.8966875..wav",
|
103 |
+
f"{EVENTS_FOLDER}/test_de_easy__part3_start0.7966875_end1.089125..wav",
|
104 |
+
f"{EVENTS_FOLDER}/test_de_easy__part4_start0.989125_end1.3200625..wav",
|
105 |
+
],
|
106 |
+
"audio_durations": [
|
107 |
+
0.4733125,
|
108 |
+
0.33093750000000005,
|
109 |
+
0.2924375,
|
110 |
+
0.2924374999999999,
|
111 |
+
0.3309374999999999,
|
112 |
+
],
|
113 |
+
"real_transcript": "hallo wie geht es dir",
|
114 |
+
"ipa_transcript": "haloː viː ɡeːt ɛːs diːɐ̯",
|
115 |
+
"pronunciation_accuracy": 100.0,
|
116 |
+
"real_transcripts": "Hallo, wie geht es dir?",
|
117 |
+
"matched_transcripts": "hallo wie geht es dir",
|
118 |
+
"real_transcripts_ipa": "haloː, viː ɡeːt ɛːs diːr?",
|
119 |
+
"matched_transcripts_ipa": "haloː viː ɡeːt ɛːs diːɐ̯",
|
120 |
+
"pair_accuracy_category": "0 0 0 0 0",
|
121 |
+
"start_time": "0.0 0.3733125 0.60425 0.7966875 0.989125",
|
122 |
+
"end_time": "0.4733125 0.70425 0.8966875 1.089125 1.3200625",
|
123 |
+
"is_letter_correct_all_words": "111111 111 1111 11 1111 ",
|
124 |
+
},
|
125 |
+
"en": {
|
126 |
+
"audio_files": [
|
127 |
+
f"{EVENTS_FOLDER}/test_en_easy__part0_start0.0_end0.1625..wav",
|
128 |
+
f"{EVENTS_FOLDER}/test_en_easy__part1_start0.0625_end0.3875..wav",
|
129 |
+
f"{EVENTS_FOLDER}/test_en_easy__part2_start0.2875_end0.575..wav",
|
130 |
+
f"{EVENTS_FOLDER}/test_en_easy__part3_start0.475_end0.8..wav",
|
131 |
+
f"{EVENTS_FOLDER}/test_en_easy__part4_start0.7_end0.9875..wav",
|
132 |
+
],
|
133 |
+
"audio_durations": [
|
134 |
+
0.1625,
|
135 |
+
0.325,
|
136 |
+
0.2875,
|
137 |
+
0.32500000000000007,
|
138 |
+
0.2875000000000001,
|
139 |
+
],
|
140 |
+
"real_transcript": "i there how are you",
|
141 |
+
"ipa_transcript": "aɪ ðɛr haʊ ər ju",
|
142 |
+
"pronunciation_accuracy": 94.0,
|
143 |
+
"real_transcripts": "Hi there, how are you?",
|
144 |
+
"matched_transcripts": "i there how are you",
|
145 |
+
"real_transcripts_ipa": "haɪ ðɛr, haʊ ər ju?",
|
146 |
+
"matched_transcripts_ipa": "aɪ ðɛr haʊ ər ju",
|
147 |
+
"pair_accuracy_category": "2 0 0 0 0",
|
148 |
+
"start_time": "0.0 0.0625 0.2875 0.475 0.7",
|
149 |
+
"end_time": "0.1625 0.3875 0.575 0.8 0.9875",
|
150 |
+
"is_letter_correct_all_words": "01 111111 111 111 1111 ",
|
151 |
+
},
|
152 |
+
}
|
153 |
+
expected_get_accuracy_lambda = {
|
154 |
+
"de": {
|
155 |
+
"real_transcript": "ich bin om werbst du wille freude wo no wie essen",
|
156 |
+
"ipa_transcript": "ɪç biːn oːm vɛːrbst duː vɪlɛː frɔɪ̯dɛː voː noː viː ɛzɛːn",
|
157 |
+
"pronunciation_accuracy": 62.0,
|
158 |
+
"real_transcripts": "Ich bin Tom, wer bist du? Viel Freude. Wollen wir essen?",
|
159 |
+
"matched_transcripts": "ich bin om - - du wille freude wo wie essen",
|
160 |
+
"real_transcripts_ipa": "ɪç biːn toːm, vɐ bɪst duː? fiːl frɔɪ̯dɛː. vɔln̩ viːɐ̯ ɛzɛːn?",
|
161 |
+
"matched_transcripts_ipa": "ɪç biːn oːm - - duː vɪlə frɔɪ̯də voː viː ɛzɛːn",
|
162 |
+
"pair_accuracy_category": "0 0 1 2 2 0 2 0 2 1 0",
|
163 |
+
"start_time": "0.625875 0.8644375 1.3415625 5.7945625 5.7945625 2.772875 3.4885 3.886125 4.919875 5.51625 5.7945625",
|
164 |
+
"end_time": "0.9644375 1.203 1.6800625 6.371625 6.371625 3.1114375 3.986125 4.46325 5.258375 5.815 6.371625",
|
165 |
+
"is_letter_correct_all_words": "111 111 0111 000 0000 111 0101 1111111 110000 110 111111 ",
|
166 |
+
},
|
167 |
+
"en": {
|
168 |
+
"real_transcript": "tom weing as someone else ca",
|
169 |
+
"ipa_transcript": "tɑm weing ɛz ˈsəmˌwən ɛls ˈsiˈeɪ",
|
170 |
+
"pronunciation_accuracy": 75.0,
|
171 |
+
"real_transcripts": "Tom is wearing someone else's coat.",
|
172 |
+
"matched_transcripts": "tom - weing someone else ca",
|
173 |
+
"real_transcripts_ipa": "tɑm ɪz ˈwɛrɪŋ ˈsəmˌwən ˈɛlsɪz koʊt.",
|
174 |
+
"matched_transcripts_ipa": "tɑm weing ˈsəmˌwən ɛls ˈsiˈeɪ",
|
175 |
+
"pair_accuracy_category": "0 2 0 0 0 2",
|
176 |
+
"start_time": "1.4094375 3.4605 2.0405 2.671625 3.0660625 3.4605",
|
177 |
+
"end_time": "1.903875 3.7971875 2.5744375 3.1660625 3.5605 3.7971875",
|
178 |
+
"is_letter_correct_all_words": "111 00 1100111 1111111 111110 10101 ",
|
179 |
+
},
|
180 |
+
}
|
181 |
+
|
182 |
+
|
183 |
+
def set_seed(seed=0):
|
184 |
+
import random
|
185 |
+
import torch
|
186 |
+
import numpy as np
|
187 |
|
188 |
+
random.seed(seed)
|
189 |
+
np.random.seed(seed)
|
190 |
+
torch.manual_seed(seed)
|
191 |
|
192 |
+
|
193 |
+
def get_request_body(language, text, base64_audio=None):
|
194 |
+
body = json.dumps(
|
195 |
+
{
|
196 |
+
"language": language,
|
197 |
+
"title": text,
|
198 |
+
"base64Audio": f"data:audio/ogg;;base64,{base64_audio}",
|
199 |
+
}
|
200 |
+
)
|
201 |
+
return {"body": body}
|
202 |
+
|
203 |
+
|
204 |
+
def assert_raises_get_speech_to_score_dict(
|
205 |
+
cls, real_text, file_bytes_or_audiotmpfile, language, exc, error_message
|
206 |
+
):
|
207 |
from aip_trainer.lambdas import lambdaSpeechToScore
|
208 |
|
209 |
+
with cls.assertRaises(exc):
|
210 |
try:
|
211 |
lambdaSpeechToScore.get_speech_to_score_dict(
|
212 |
+
real_text,
|
213 |
+
file_bytes_or_audiotmpfile,
|
214 |
+
language,
|
215 |
+
remove_random_file=False,
|
216 |
)
|
217 |
except exc as e:
|
218 |
+
cls.assertEqual(str(e), error_message)
|
219 |
raise e
|
220 |
|
221 |
|
222 |
def check_value_by_field(value, match):
|
223 |
import re
|
224 |
+
|
225 |
assert len(value.strip()) > 0
|
226 |
for word in value.lstrip().rstrip().split(" "):
|
227 |
word_check = re.findall(match, word.strip())
|
|
|
236 |
return output
|
237 |
|
238 |
|
239 |
+
def check_output(cls, output, expected_output, check_audio_files=False):
|
240 |
from pathlib import Path
|
241 |
+
|
242 |
+
cls.maxDiff = None
|
243 |
try:
|
244 |
+
cls.assertDictEqual(output, expected_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
if check_audio_files:
|
246 |
audio_files = output["audio_files"]
|
247 |
audio_durations = output["audio_durations"]
|
|
|
253 |
app_logger.info(f"path_audio_file:{path_audio_file}.")
|
254 |
assert path_audio_file.is_file()
|
255 |
path_audio_file.unlink()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
except Exception as e:
|
257 |
app_logger.error(f"e:{e}.")
|
258 |
raise e
|
259 |
|
260 |
|
261 |
+
def assert_get_speech_to_score_ok(cls, language, expected):
|
262 |
+
from aip_trainer.lambdas import lambdaSpeechToScore
|
263 |
+
|
264 |
+
set_seed()
|
265 |
+
path = EVENTS_FOLDER / f"test_{language}.wav"
|
266 |
+
output = lambdaSpeechToScore.get_speech_to_score_dict(
|
267 |
+
real_text=text_dict[language],
|
268 |
+
file_bytes_or_audiotmpfile=str(path),
|
269 |
+
language=language,
|
270 |
+
remove_random_file=False,
|
271 |
+
)
|
272 |
+
cls.assertDictEqual(output, expected)
|
273 |
+
|
274 |
+
|
275 |
+
def assert_get_speech_to_score_ok_remove_input_file(cls, language, expected):
|
276 |
+
import shutil
|
277 |
+
from aip_trainer.lambdas import lambdaSpeechToScore
|
278 |
+
|
279 |
+
set_seed()
|
280 |
+
path = EVENTS_FOLDER / f"test_{language}.wav"
|
281 |
+
path2 = EVENTS_FOLDER / f"test2_{language}.wav"
|
282 |
+
shutil.copy(path, path2)
|
283 |
+
assert path2.exists() and path2.is_file()
|
284 |
+
output = lambdaSpeechToScore.get_speech_to_score_dict(
|
285 |
+
real_text=text_dict[language],
|
286 |
+
file_bytes_or_audiotmpfile=str(path2),
|
287 |
+
language=language,
|
288 |
+
remove_random_file=True,
|
289 |
+
)
|
290 |
+
assert not path2.exists()
|
291 |
+
cls.assertDictEqual(output, expected)
|
292 |
+
|
293 |
+
|
294 |
+
def assert_get_speech_to_score_tuple_ok(cls, language, expected, expected_num_words):
|
295 |
+
from aip_trainer.lambdas import lambdaSpeechToScore
|
296 |
+
|
297 |
+
set_seed()
|
298 |
+
path = EVENTS_FOLDER / f"test_{language}.wav"
|
299 |
+
(
|
300 |
+
real_transcripts,
|
301 |
+
is_letter_correct_all_words,
|
302 |
+
pronunciation_accuracy,
|
303 |
+
ipa_transcript,
|
304 |
+
real_transcripts_ipa,
|
305 |
+
num_words,
|
306 |
+
first_audio_file,
|
307 |
+
dumped,
|
308 |
+
) = lambdaSpeechToScore.get_speech_to_score_tuple(
|
309 |
+
real_text=text_dict[language],
|
310 |
+
file_bytes_or_audiotmpfile=str(path),
|
311 |
+
language=language,
|
312 |
+
remove_random_file=False,
|
313 |
+
)
|
314 |
+
assert real_transcripts == text_dict[language]
|
315 |
+
expected_output = expected[language]
|
316 |
+
assert is_letter_correct_all_words.strip() == expected_output["is_letter_correct_all_words"].strip()
|
317 |
+
assert pronunciation_accuracy == expected_output["pronunciation_accuracy"]
|
318 |
+
assert ipa_transcript.strip() == expected_output["ipa_transcript"].strip()
|
319 |
+
assert real_transcripts_ipa.strip() == expected_output["real_transcripts_ipa"]
|
320 |
+
assert num_words == expected_num_words
|
321 |
+
first_audio_file_path = Path(first_audio_file)
|
322 |
+
assert first_audio_file_path.exists() and first_audio_file_path.is_file()
|
323 |
+
json_loaded = json.loads(dumped)
|
324 |
+
check_output(cls, json_loaded, expected_output, check_audio_files=True)
|
325 |
+
|
326 |
+
|
327 |
+
def assert_get_selected_word_valid_index_ok(language, expected):
|
328 |
+
set_seed()
|
329 |
+
path = EVENTS_FOLDER / f"test_{language}_easy.wav"
|
330 |
+
input_text = text_dict[language]
|
331 |
+
_, _, _, _, _, _, _, output_json = lambdaSpeechToScore.get_speech_to_score_tuple(
|
332 |
+
input_text, str(path), language, False
|
333 |
+
)
|
334 |
+
idx_recorded_word = 2
|
335 |
+
output_loaded = json.loads(output_json)
|
336 |
+
audio_file, word, duration = lambdaSpeechToScore.get_selected_word(
|
337 |
+
idx_recorded_word, output_json
|
338 |
+
)
|
339 |
+
audio_file_path = Path(audio_file)
|
340 |
+
assert audio_file_path.exists() and audio_file_path.is_file()
|
341 |
+
expected_end_time_list = expected[language]["audio_durations"]
|
342 |
+
expected_end_time = expected_end_time_list[idx_recorded_word]
|
343 |
+
assert duration == expected_end_time
|
344 |
+
words_list = text_dict[language].split()
|
345 |
+
assert word == words_list[idx_recorded_word]
|
346 |
+
for file_to_del in output_loaded["audio_files"]:
|
347 |
+
Path(file_to_del).unlink()
|
348 |
+
|
349 |
+
|
350 |
+
def assert_get_selected_word_invalid_index(cls, language):
|
351 |
+
set_seed()
|
352 |
+
path = EVENTS_FOLDER / f"test_{language}_easy.wav"
|
353 |
+
_, _, _, _, _, _, _, output_json = lambdaSpeechToScore.get_speech_to_score_tuple(
|
354 |
+
text_dict[language], str(path), language, False
|
355 |
+
)
|
356 |
+
with cls.assertRaises(IndexError):
|
357 |
+
try:
|
358 |
+
lambdaSpeechToScore.get_selected_word(120, output_json)
|
359 |
+
except IndexError as ie:
|
360 |
+
msg = str(ie)
|
361 |
+
assert msg == "list index out of range"
|
362 |
+
raise ie
|
363 |
+
|
364 |
+
|
365 |
class TestGetAccuracyFromRecordedAudio(unittest.TestCase):
|
366 |
def setUp(self):
|
367 |
if platform.system() == "Windows" or platform.system() == "Win32":
|
|
|
374 |
del os.environ["PYTHONUTF8"]
|
375 |
|
376 |
def test_GetAccuracyFromRecordedAudio(self):
|
377 |
+
set_seed()
|
378 |
with open(EVENTS_FOLDER / "GetAccuracyFromRecordedAudio.json", "r") as src:
|
379 |
inputs_outputs = json.load(src)
|
380 |
inputs = inputs_outputs["inputs"]
|
381 |
+
for language, event_content in inputs.items():
|
382 |
+
current_expected_output = expected_get_accuracy_lambda[language]
|
|
|
383 |
output = lambdaSpeechToScore.lambda_handler(event_content, [])
|
384 |
output = json.loads(output)
|
385 |
+
expected_get_accuracy_lambda[language] = output
|
386 |
app_logger.info(
|
387 |
f"output type:{type(output)}, expected_output type:{type(current_expected_output)}."
|
388 |
)
|
389 |
+
self.assertDictEqual(output, current_expected_output)
|
390 |
|
391 |
def test_lambda_handler_empty_text(self):
|
392 |
from aip_trainer.lambdas import lambdaSpeechToScore
|
|
|
415 |
)
|
416 |
|
417 |
def test_get_speech_to_score_en_ok(self):
|
418 |
+
assert_get_speech_to_score_ok(self, "en", expected_get_speech_to_score["en"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
|
420 |
def test_get_speech_to_score_de_ok(self):
|
421 |
+
assert_get_speech_to_score_ok(self, "de", expected_get_speech_to_score["de"])
|
422 |
|
423 |
+
def test_get_speech_to_score_en_ok_remove_input_file(self):
|
424 |
+
assert_get_speech_to_score_ok_remove_input_file(
|
425 |
+
self, "en", expected_get_speech_to_score["en"]
|
|
|
|
|
|
|
|
|
426 |
)
|
|
|
427 |
|
428 |
def test_get_speech_to_score_de_ok_remove_input_file(self):
|
429 |
+
assert_get_speech_to_score_ok_remove_input_file(
|
430 |
+
self, "de", expected_get_speech_to_score["de"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
)
|
|
|
|
|
432 |
|
433 |
def test_get_speech_to_score_tuple_de_ok(self):
|
434 |
+
assert_get_speech_to_score_tuple_ok(
|
435 |
+
self, "de", expected_with_audio_files_splitted_list, expected_num_words=5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
437 |
|
438 |
def test_get_speech_to_score_tuple_en_ok(self):
|
439 |
+
assert_get_speech_to_score_tuple_ok(
|
440 |
+
self, "en", expected_with_audio_files_splitted_list, expected_num_words=5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
441 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
|
443 |
def test_get_speech_to_score_dict__de_empty_input_text(self):
|
444 |
language = "de"
|
445 |
path = EVENTS_FOLDER / f"test_{language}.wav"
|
446 |
+
assert_raises_get_speech_to_score_dict(
|
447 |
+
self,
|
448 |
+
"",
|
449 |
+
str(path),
|
450 |
+
language,
|
451 |
+
ValueError,
|
452 |
+
"cannot read an empty/None text: ''...",
|
453 |
+
)
|
454 |
|
455 |
def test_get_speech_to_score_dict__en_empty_input_text(self):
|
456 |
language = "en"
|
457 |
path = EVENTS_FOLDER / f"test_{language}.wav"
|
458 |
+
assert_raises_get_speech_to_score_dict(
|
459 |
+
self,
|
460 |
+
"",
|
461 |
+
str(path),
|
462 |
+
language,
|
463 |
+
ValueError,
|
464 |
+
"cannot read an empty/None text: ''...",
|
465 |
+
)
|
466 |
|
467 |
def test_get_speech_to_score_dict__de_empty_input_file(self):
|
468 |
language = "de"
|
469 |
+
assert_raises_get_speech_to_score_dict(
|
470 |
+
self,
|
471 |
+
"text fake",
|
472 |
+
"",
|
473 |
+
language,
|
474 |
+
OSError,
|
475 |
+
"cannot read an empty/None file: ''...",
|
476 |
+
)
|
477 |
|
478 |
def test_get_speech_to_score_dict__en_empty_input_file(self):
|
479 |
language = "en"
|
480 |
+
assert_raises_get_speech_to_score_dict(
|
481 |
+
self,
|
482 |
+
"text fake",
|
483 |
+
"",
|
484 |
+
language,
|
485 |
+
OSError,
|
486 |
+
"cannot read an empty/None file: ''...",
|
487 |
+
)
|
488 |
+
|
489 |
def test_get_speech_to_score_dict__empty_language(self):
|
490 |
+
assert_raises_get_speech_to_score_dict(
|
491 |
+
self,
|
492 |
+
"text fake",
|
493 |
+
"fake_file",
|
494 |
+
"",
|
495 |
+
NotImplementedError,
|
496 |
+
"Not tested/supported with '' language...",
|
497 |
+
)
|
498 |
+
|
499 |
def test_get_speech_to_score_dict__empty_language(self):
|
500 |
language = "en"
|
501 |
path_file = str(EVENTS_FOLDER / "empty_file.wav")
|
502 |
+
assert_raises_get_speech_to_score_dict(
|
503 |
+
self,
|
504 |
+
"text fake",
|
505 |
+
path_file,
|
506 |
+
language,
|
507 |
+
OSError,
|
508 |
+
f"cannot read an empty file: '{path_file}'...",
|
509 |
+
)
|
510 |
|
511 |
def test_get_selected_word_valid_index_de_ok(self):
|
512 |
+
assert_get_selected_word_valid_index_ok(
|
513 |
+
"de", expected_with_selected_word_valid_index
|
|
|
|
|
|
|
|
|
|
|
514 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
515 |
|
516 |
def test_get_selected_word_valid_index_en_ok(self):
|
517 |
+
assert_get_selected_word_valid_index_ok(
|
518 |
+
"en", expected_with_selected_word_valid_index
|
|
|
|
|
|
|
|
|
519 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
520 |
|
521 |
def test_get_selected_word_invalid_index_de(self):
|
522 |
+
assert_get_selected_word_invalid_index(self, "de")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
523 |
|
524 |
def test_get_selected_word_invalid_index_en(self):
|
525 |
+
assert_get_selected_word_invalid_index(self, "en")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
526 |
|
527 |
def test_get_selected_word_empty_transcripts(self):
|
528 |
+
raw_json_output = json.dumps(
|
529 |
+
{"audio_files": [], "real_transcripts": "", "audio_durations": []}
|
530 |
+
)
|
|
|
|
|
531 |
idx_recorded_word = 0
|
532 |
with self.assertRaises(IndexError):
|
533 |
lambdaSpeechToScore.get_selected_word(idx_recorded_word, raw_json_output)
|
|
|
537 |
path = str(EVENTS_FOLDER / f"test_{language}.wav")
|
538 |
start_time = [0.0, 1.0, 2.0]
|
539 |
end_time = [1.0, 2.0, 2.5]
|
540 |
+
|
541 |
audio_files, audio_durations = lambdaSpeechToScore.get_splitted_audio_file(
|
542 |
+
audiotmpfile=path, start_time=start_time, end_time=end_time
|
|
|
|
|
543 |
)
|
544 |
|
545 |
assert len(audio_files) == len(start_time)
|
|
|
559 |
with self.assertRaises(LibsndfileError):
|
560 |
try:
|
561 |
lambdaSpeechToScore.get_splitted_audio_file(
|
562 |
+
audiotmpfile="", start_time=start_time, end_time=end_time
|
|
|
|
|
563 |
)
|
564 |
except LibsndfileError as lsfe:
|
565 |
msg = str(lsfe)
|
|
|
577 |
with self.assertRaises(LibsndfileError):
|
578 |
try:
|
579 |
lambdaSpeechToScore.get_splitted_audio_file(
|
580 |
+
audiotmpfile=str(path), start_time=start_time, end_time=end_time
|
|
|
|
|
581 |
)
|
582 |
except LibsndfileError as lsfe:
|
583 |
msg = str(lsfe)
|
584 |
+
assert msg == "Internal psf_fseek() failed."
|
585 |
raise lsfe
|
586 |
|
587 |
|
tests/utils/test_utilities.py
CHANGED
@@ -40,9 +40,9 @@ class TestUtilities(unittest.TestCase):
|
|
40 |
app_logger.info(f"output_hash test_en: {output_hash}")
|
41 |
assert b'Dsvmm+mj/opHnmKLT7wIqyhqMLeIuVP4hTWi+DAXS8Y=' == output_hash
|
42 |
|
43 |
-
output_hash = hash_calculate(EVENTS_FOLDER / "
|
44 |
app_logger.info(f"output_hash json: {output_hash}")
|
45 |
-
assert b'
|
46 |
|
47 |
|
48 |
if __name__ == '__main__':
|
|
|
40 |
app_logger.info(f"output_hash test_en: {output_hash}")
|
41 |
assert b'Dsvmm+mj/opHnmKLT7wIqyhqMLeIuVP4hTWi+DAXS8Y=' == output_hash
|
42 |
|
43 |
+
output_hash = hash_calculate(EVENTS_FOLDER / "example.json", is_file=True)
|
44 |
app_logger.info(f"output_hash json: {output_hash}")
|
45 |
+
assert b'aLGnsOa1Z3QmfilSPybdVcUHcjgd5ntOZh6mbQDEy2w=' == output_hash
|
46 |
|
47 |
|
48 |
if __name__ == '__main__':
|