Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,20 +24,25 @@ def assess_pronunciation(audio_file):
|
|
24 |
|
25 |
# Recognize speech and assess pronunciation
|
26 |
result = recognizer.recognize_once()
|
27 |
-
pronunciation_result = speechsdk.PronunciationAssessmentResult(result)
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
|
42 |
# Create Gradio interface
|
43 |
interface = gr.Interface(
|
|
|
24 |
|
25 |
# Recognize speech and assess pronunciation
|
26 |
result = recognizer.recognize_once()
|
|
|
27 |
|
28 |
+
# Check if the result is valid
|
29 |
+
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
|
30 |
+
pronunciation_result = speechsdk.PronunciationAssessmentResult(result)
|
31 |
+
|
32 |
+
# Extract and format the results
|
33 |
+
accuracy_score = pronunciation_result.accuracy_score
|
34 |
+
fluency_score = pronunciation_result.fluency_score
|
35 |
+
completeness_score = pronunciation_result.completeness_score
|
36 |
+
prosody_score = pronunciation_result.prosody_score
|
37 |
|
38 |
+
return {
|
39 |
+
"Accuracy": accuracy_score,
|
40 |
+
"Fluency": fluency_score,
|
41 |
+
"Completeness": completeness_score,
|
42 |
+
"Prosody": prosody_score
|
43 |
+
}
|
44 |
+
else:
|
45 |
+
return {"Error": "Speech could not be recognized. Please try again with a clearer audio."}
|
46 |
|
47 |
# Create Gradio interface
|
48 |
interface = gr.Interface(
|