Spaces:
Sleeping
Sleeping
Update app.py
Browse files10 unmodified lines111213141516161718192034 unmodified lines555657575859606110 unmodified lines7273747576777879808182838485868788899011 unmodified lines1021031041051069210710894109110961111121131141151161171181198 unmodified lines12812913013113213313413511613613713813910 unmodified linesfrom src.audio_preprocessing import assess_pronunciation_qualityfrom datetime import datetimefrom pathlib import Pathimport re
@spaces.GPUdef check_pronunciation(reference_audio, input_audio, threshold, wavlm_layer):def check_pronunciation(reference_audio, input_audio, threshold, wavlm_layer, labels_data=None, input_number=None): wavlm_layer = int(wavlm_layer)
timing_results = []34 unmodified lines raise ValueError("DTW computation failed.")
PronunciationChecker.plot_waveform_with_overlay(ref_wav, sr, dist_matrix, path, "ref", threshold) PronunciationChecker.plot_waveform_with_overlay(ref_wav, sr, dist_matrix, path, "ref", threshold, labels_data, input_number) log_timing("Visualization Generation")
# Save the visualization to a temporary image file10 unmodified lines # Return the image file path for Gradio to display return tmp_path, quality_score, needs_repeat, timing_analysis
def parse_labels_file(labels_file): labels_data = [] with open(labels_file, 'r') as f: for line in f: parts = re.split(r'[\t ]+', line) if len(parts) < 3: continue start, end = map(float, parts[:2]) grapheme = parts[2] boolean_labels = list(map(int, parts[3:])) labels_data.append((start, end, grapheme, *boolean_labels)) return labels_data
@spaces.GPUdef run_tests(threshold=0.4, wavlm_layer=24): # Create a directory for storing plots if it doesn't exist11 unmodified lines if test_word_dir.is_dir(): word = test_word_dir.name ref_file = test_word_dir / "ref.wav" labels_file = test_word_dir / "labels.txt"
if not ref_file.exists(): if not ref_file.exists() or not labels_file.exists(): test_cases.append({ "heading": f"Error: Missing reference file for '{word}'", "heading": f"Error: Missing files for '{word}'", "plot": None, "text": f"Reference file not found for test word '{word}'." "text": f"Missing required files (ref.wav or labels.txt) for test word '{word}'." }) continue
labels_data = parse_labels_file(labels_file)
for input_file in test_word_dir.glob("input_*.wav"): if not input_file.exists(): test_cases.append({8 unmodified lines plot_filename = f"{word}_{input_file.stem}_{datetime.now().strftime('%H%M%S')}.png" plot_path = plots_dir / plot_filename
input_number = str(input_file.stem).split('_')[1] input_number = int(input_number)-1
# Run the pronunciation checker tmp_path, quality_score, needs_repeat, timing_analysis = check_pronunciation( ref_file, input_file, threshold, wavlm_layer ref_file, input_file, threshold, wavlm_layer, labels_data, input_number ) # Move the plot to our persistent directoryapp.py+26-6