Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,8 +11,9 @@ def assess_pronunciation(audio_file):
|
|
| 11 |
audio_config = speechsdk.audio.AudioConfig(filename=audio_file)
|
| 12 |
|
| 13 |
# Create pronunciation assessment config
|
|
|
|
| 14 |
pronunciation_config = speechsdk.PronunciationAssessmentConfig(
|
| 15 |
-
reference_text=
|
| 16 |
grading_system=speechsdk.PronunciationAssessmentGradingSystem.HundredMark,
|
| 17 |
granularity=speechsdk.PronunciationAssessmentGranularity.Phoneme
|
| 18 |
)
|
|
@@ -24,9 +25,10 @@ def assess_pronunciation(audio_file):
|
|
| 24 |
|
| 25 |
# Recognize speech and assess pronunciation
|
| 26 |
result = recognizer.recognize_once()
|
| 27 |
-
|
| 28 |
# Debug information
|
| 29 |
print(f"Recognition result reason: {result.reason}")
|
|
|
|
| 30 |
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
|
| 31 |
pronunciation_result = speechsdk.PronunciationAssessmentResult(result)
|
| 32 |
|
|
@@ -42,10 +44,17 @@ def assess_pronunciation(audio_file):
|
|
| 42 |
"Completeness": completeness_score,
|
| 43 |
"Prosody": prosody_score
|
| 44 |
}
|
| 45 |
-
|
| 46 |
-
print(
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Create Gradio interface
|
| 51 |
interface = gr.Interface(
|
|
|
|
| 11 |
audio_config = speechsdk.audio.AudioConfig(filename=audio_file)
|
| 12 |
|
| 13 |
# Create pronunciation assessment config
|
| 14 |
+
reference_text = "你好"
|
| 15 |
pronunciation_config = speechsdk.PronunciationAssessmentConfig(
|
| 16 |
+
reference_text=reference_text,
|
| 17 |
grading_system=speechsdk.PronunciationAssessmentGradingSystem.HundredMark,
|
| 18 |
granularity=speechsdk.PronunciationAssessmentGranularity.Phoneme
|
| 19 |
)
|
|
|
|
| 25 |
|
| 26 |
# Recognize speech and assess pronunciation
|
| 27 |
result = recognizer.recognize_once()
|
| 28 |
+
|
| 29 |
# Debug information
|
| 30 |
print(f"Recognition result reason: {result.reason}")
|
| 31 |
+
|
| 32 |
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
|
| 33 |
pronunciation_result = speechsdk.PronunciationAssessmentResult(result)
|
| 34 |
|
|
|
|
| 44 |
"Completeness": completeness_score,
|
| 45 |
"Prosody": prosody_score
|
| 46 |
}
|
| 47 |
+
elif result.reason == speechsdk.ResultReason.NoMatch:
|
| 48 |
+
print("NOMATCH: Speech could not be recognized.")
|
| 49 |
+
return {"Error": "Speech could not be recognized. Please try again with a clearer audio."}
|
| 50 |
+
elif result.reason == speechsdk.ResultReason.Canceled:
|
| 51 |
+
cancellation_details = speechsdk.CancellationDetails(result)
|
| 52 |
+
print(f"CANCELED: Reason={cancellation_details.reason}")
|
| 53 |
+
if cancellation_details.reason == speechsdk.CancellationReason.Error:
|
| 54 |
+
print(f"CANCELED: ErrorCode={cancellation_details.error_code}")
|
| 55 |
+
print(f"CANCELED: ErrorDetails={cancellation_details.error_details}")
|
| 56 |
+
print("CANCELED: Did you update the subscription info?")
|
| 57 |
+
return {"Error": f"Speech recognition canceled: {cancellation_details.error_details}"}
|
| 58 |
|
| 59 |
# Create Gradio interface
|
| 60 |
interface = gr.Interface(
|