alibabasglab commited on
Commit
58f8c9b
·
verified ·
1 Parent(s): ced5887

Update speechscore.py

Browse files
Files changed (1) hide show
  1. speechscore.py +11 -8
speechscore.py CHANGED
@@ -20,7 +20,7 @@ from scores.cbak import CBAK
20
  from scores.covl import COVL
21
  from scores.mcd import MCD
22
 
23
- def compute_mean_results(*results):
24
  mean_result = {}
25
 
26
  # Use the first dictionary as a reference for keys
@@ -28,10 +28,13 @@ def compute_mean_results(*results):
28
  # If the value is a nested dictionary, recurse
29
  if isinstance(results[0][key], dict):
30
  nested_results = [d[key] for d in results]
31
- mean_result[key] = compute_mean_results(*nested_results)
32
  # Otherwise, compute the mean of the values
33
  else:
34
- mean_result[key] = sum(d[key] for d in results) / len(results)
 
 
 
35
 
36
  return mean_result
37
 
@@ -46,7 +49,7 @@ class ScoresList:
46
  def __str__(self):
47
  return 'Scores: ' + ' '.join([x.name for x in self.scores])
48
 
49
- def __call__(self, test_path, reference_path, window=None, score_rate=None, return_mean=False):
50
  """
51
  window: float
52
  the window length in seconds to use for scoring the files.
@@ -68,7 +71,7 @@ class ScoresList:
68
  data['rate'] = score_rate
69
 
70
  for score in self.scores:
71
- result_score = score.scoring(data, window, score_rate)
72
  results[score.name] = result_score
73
  else:
74
  if os.path.isdir(test_path):
@@ -81,18 +84,18 @@ class ScoresList:
81
  else:
82
  data = self.audio_reader(test_path+'/'+audio_id, None)
83
  for score in self.scores:
84
- result_score = score.scoring(data, window, score_rate)
85
  results_id[score.name] = result_score
86
  results[audio_id] = results_id
87
 
88
  elif os.path.isfile(test_path):
89
  data = self.audio_reader(test_path, reference_path)
90
  for score in self.scores:
91
- result_score = score.scoring(data, window, score_rate)
92
  results[score.name] = result_score
93
 
94
  if return_mean:
95
- mean_result = compute_mean_results(*results.values())
96
  results['Mean_Score'] = mean_result
97
 
98
  return results
 
20
  from scores.covl import COVL
21
  from scores.mcd import MCD
22
 
23
+ def compute_mean_results(*results, round_digits=None):
24
  mean_result = {}
25
 
26
  # Use the first dictionary as a reference for keys
 
28
  # If the value is a nested dictionary, recurse
29
  if isinstance(results[0][key], dict):
30
  nested_results = [d[key] for d in results]
31
+ mean_result[key] = compute_mean_results(*nested_results, round_digits=round_digits)
32
  # Otherwise, compute the mean of the values
33
  else:
34
+ if round_digits is not None:
35
+ mean_result[key] = round(sum(d[key] for d in results) / len(results), round_digits)
36
+ else:
37
+ mean_result[key] = sum(d[key] for d in results) / len(results)
38
 
39
  return mean_result
40
 
 
49
  def __str__(self):
50
  return 'Scores: ' + ' '.join([x.name for x in self.scores])
51
 
52
+ def __call__(self, test_path, reference_path, window=None, score_rate=None, return_mean=False, round_digits=None):
53
  """
54
  window: float
55
  the window length in seconds to use for scoring the files.
 
71
  data['rate'] = score_rate
72
 
73
  for score in self.scores:
74
+ result_score = score.scoring(data, window, score_rate, round_digits)
75
  results[score.name] = result_score
76
  else:
77
  if os.path.isdir(test_path):
 
84
  else:
85
  data = self.audio_reader(test_path+'/'+audio_id, None)
86
  for score in self.scores:
87
+ result_score = score.scoring(data, window, score_rate, round_digits)
88
  results_id[score.name] = result_score
89
  results[audio_id] = results_id
90
 
91
  elif os.path.isfile(test_path):
92
  data = self.audio_reader(test_path, reference_path)
93
  for score in self.scores:
94
+ result_score = score.scoring(data, window, score_rate, round_digits)
95
  results[score.name] = result_score
96
 
97
  if return_mean:
98
+ mean_result = compute_mean_results(*results.values(), round_digits=round_digits)
99
  results['Mean_Score'] = mean_result
100
 
101
  return results