alessandro trinca tornidor commited on
Commit
2f5403b
·
1 Parent(s): 9c11a5e

feat: support python 3.10, update test cases

Browse files
lambdaSpeechToScore.py CHANGED
@@ -1,10 +1,13 @@
1
  import base64
2
  import json
3
- import os
4
  from pathlib import Path
5
  import tempfile
6
  import time
7
- from typing import Dict, Any, LiteralString
 
 
 
 
8
 
9
  import audioread
10
  import numpy as np
@@ -51,7 +54,8 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
51
  output = get_speech_to_score_dict(
52
  real_text=real_text, file_bytes_or_audiotmpfile=file_bytes_or_audiotmpfile, language=language, use_dtw=use_dtw
53
  )
54
- output["pronunciation_accuracy"] = f"{int(output["pronunciation_accuracy"])}"
 
55
  output = json.dumps(output)
56
  app_logger.debug(f"output: {output} ...")
57
  return output
@@ -59,7 +63,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
59
 
60
  def get_speech_to_score_dict(
61
  real_text: str, file_bytes_or_audiotmpfile: str | bytes | dict, language: str = "en", extension: str = tmp_audio_extension, use_dtw: bool = False
62
- ) -> Dict[str | Any, float | LiteralString | str | Any]:
63
  """
64
  Process the audio file and return a dictionary with speech-to-score results.
65
 
@@ -197,8 +201,8 @@ def get_speech_to_score_tuple(real_text: str, file_bytes_or_audiotmpfile: str |
197
  del output["random_file_name"]
198
  real_transcripts = output['real_transcripts']
199
  is_letter_correct_all_words = output['is_letter_correct_all_words']
200
- pronunciation_accuracy = f"{output["pronunciation_accuracy"]:.2f}"
201
- output["pronunciation_accuracy"] = pronunciation_accuracy
202
  ipa_transcript = output['ipa_transcript']
203
  real_transcripts_ipa = output['real_transcripts_ipa']
204
  end_time = [float(x) for x in output['end_time'].split(" ")]
 
1
  import base64
2
  import json
 
3
  from pathlib import Path
4
  import tempfile
5
  import time
6
+ from typing import Dict, Any
7
+ try:
8
+ from typing import LiteralString
9
+ except ImportError:
10
+ from typing_extensions import LiteralString
11
 
12
  import audioread
13
  import numpy as np
 
54
  output = get_speech_to_score_dict(
55
  real_text=real_text, file_bytes_or_audiotmpfile=file_bytes_or_audiotmpfile, language=language, use_dtw=use_dtw
56
  )
57
+ pronunciation_accuracy = int(output["pronunciation_accuracy"])
58
+ output["pronunciation_accuracy"] = f"{pronunciation_accuracy}"
59
  output = json.dumps(output)
60
  app_logger.debug(f"output: {output} ...")
61
  return output
 
63
 
64
  def get_speech_to_score_dict(
65
  real_text: str, file_bytes_or_audiotmpfile: str | bytes | dict, language: str = "en", extension: str = tmp_audio_extension, use_dtw: bool = False
66
+ ) -> Dict[str | Any, float | LiteralString | str | Any]:
67
  """
68
  Process the audio file and return a dictionary with speech-to-score results.
69
 
 
201
  del output["random_file_name"]
202
  real_transcripts = output['real_transcripts']
203
  is_letter_correct_all_words = output['is_letter_correct_all_words']
204
+ pronunciation_accuracy = output['pronunciation_accuracy']
205
+ output["pronunciation_accuracy"] = f"{pronunciation_accuracy:.2f}"
206
  ipa_transcript = output['ipa_transcript']
207
  real_transcripts_ipa = output['real_transcripts_ipa']
208
  end_time = [float(x) for x in output['end_time'].split(" ")]
tests/events/expected_get_speech_to_score_tuple_ok_de.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "real_transcripts": "Hallo, wie geht es dir?",
3
  "is_letter_correct_all_words": "111111 111 1111 11 1111 ",
4
- "pronunciation_accuracy": "100.00",
5
  "ipa_transcript": " halo\u02d0, vi\u02d0 \u0261e\u02d0t \u025b\u02d0s di\u02d0r?",
6
  "real_transcripts_ipa": "halo\u02d0, vi\u02d0 \u0261e\u02d0t \u025b\u02d0s di\u02d0r?",
7
  "num_words": 5,
 
1
  {
2
  "real_transcripts": "Hallo, wie geht es dir?",
3
  "is_letter_correct_all_words": "111111 111 1111 11 1111 ",
4
+ "pronunciation_accuracy": 100.0,
5
  "ipa_transcript": " halo\u02d0, vi\u02d0 \u0261e\u02d0t \u025b\u02d0s di\u02d0r?",
6
  "real_transcripts_ipa": "halo\u02d0, vi\u02d0 \u0261e\u02d0t \u025b\u02d0s di\u02d0r?",
7
  "num_words": 5,
tests/events/expected_get_speech_to_score_tuple_ok_en.json CHANGED
@@ -1,25 +1,11 @@
1
  {
2
  "real_transcripts": "Hi there, how are you?",
3
  "is_letter_correct_all_words": "11 111111 111 111 1111 ",
4
- "pronunciation_accuracy": "100.00",
5
  "ipa_transcript": "ha\u026a \u00f0\u025br, ha\u028a \u0259r ju?",
6
  "real_transcripts_ipa": "ha\u026a \u00f0\u025br, ha\u028a \u0259r ju?",
7
  "num_words": 5,
8
  "dumped": {
9
- "audio_files": [
10
- "test2_en_easy__part0_start0.0_end0.19..wav",
11
- "test2_en_easy__part1_start0.09_end0.35..wav",
12
- "test2_en_easy__part2_start0.41_end0.63..wav",
13
- "test2_en_easy__part3_start0.53_end0.75..wav",
14
- "test2_en_easy__part4_start0.65_end0.91..wav"
15
- ],
16
- "audio_durations": [
17
- 0.19,
18
- 0.26,
19
- 0.22000000000000003,
20
- 0.21999999999999997,
21
- 0.26
22
- ],
23
  "real_transcript": " Hi there, how are you?",
24
  "ipa_transcript": "ha\u026a \u00f0\u025br, ha\u028a \u0259r ju?",
25
  "pronunciation_accuracy": "100.00",
 
1
  {
2
  "real_transcripts": "Hi there, how are you?",
3
  "is_letter_correct_all_words": "11 111111 111 111 1111 ",
4
+ "pronunciation_accuracy": 100.0,
5
  "ipa_transcript": "ha\u026a \u00f0\u025br, ha\u028a \u0259r ju?",
6
  "real_transcripts_ipa": "ha\u026a \u00f0\u025br, ha\u028a \u0259r ju?",
7
  "num_words": 5,
8
  "dumped": {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  "real_transcript": " Hi there, how are you?",
10
  "ipa_transcript": "ha\u026a \u00f0\u025br, ha\u028a \u0259r ju?",
11
  "pronunciation_accuracy": "100.00",