karlhajal ahk-d commited on
Commit
21f3853
·
verified ·
1 Parent(s): 6d5e97d

Update src/audio_preprocessing.py (#1)

Browse files

- Update src/audio_preprocessing.py (9705702d0bf258a501d1601a8740dfad4515f169)


Co-authored-by: ahk-d <ahk-d@users.noreply.huggingface.co>

Files changed (1) hide show
  1. src/audio_preprocessing.py +35 -1
src/audio_preprocessing.py CHANGED
@@ -100,4 +100,38 @@ def process_wav(wav_path, target_sr, do_trim_silences=True):
100
  # Loudness normalization to -20dB
101
  audio = match_target_amplitude(audio, -20.0)
102
 
103
- return audio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  # Loudness normalization to -20dB
101
  audio = match_target_amplitude(audio, -20.0)
102
 
103
+ return audio
104
+
105
+ import numpy as np
106
+
107
+ def assess_pronunciation_quality(dist_matrix, path):
108
+ # Extract distances along the alignment path
109
+ path_distances = [dist_matrix[i, j] for i, j in zip(*path)]
110
+
111
+ # Calculate global min and max for normalization
112
+ global_min = dist_matrix.min()
113
+ global_max = dist_matrix.max()
114
+
115
+ # Normalize distances
116
+ normalized_distances = [(d - global_min) / (global_max - global_min) for d in path_distances]
117
+
118
+ # Analyze normalized distances
119
+ num_red_segments = sum(1 for d in normalized_distances if d >= 0.5)
120
+ total_segments = len(normalized_distances)
121
+ red_percentage = num_red_segments / total_segments if total_segments > 0 else 0.0
122
+
123
+ # Calculate quality score and repetition need
124
+ quality_score = 1 - red_percentage
125
+ needs_repeat = red_percentage > 0.5
126
+
127
+ # Print debug information
128
+ print(f"Raw distance stats:")
129
+ print(f" Min distance: {min(path_distances):.4f}")
130
+ print(f" Max distance: {max(path_distances):.4f}")
131
+ print(f" Mean distance: {np.mean(path_distances):.4f}")
132
+ print(f"\nNormalized distance stats:")
133
+ print(f" Number of red segments (>= 0.5): {num_red_segments}")
134
+ print(f" Total segments: {total_segments}")
135
+ print(f"\nRed percentage: {red_percentage * 100:.2f}%")
136
+
137
+ return quality_score, needs_repeat