Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,51 @@
|
|
1 |
-
import
|
2 |
import azure.cognitiveservices.speech as speechsdk
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
def transcribe_audio(file_path):
|
9 |
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
elif result.reason == speechsdk.ResultReason.NoMatch:
|
17 |
-
return "No speech could be recognized"
|
18 |
-
else:
|
19 |
-
return "Speech recognition canceled: {}".format(result.cancellation_details.reason)
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
import azure.cognitiveservices.speech as speechsdk
|
3 |
|
4 |
+
def assess_pronunciation(audio_file):
|
5 |
+
# Configure Azure Speech Service
|
6 |
+
speech_key = "YourAzureSpeechServiceKey"
|
7 |
+
service_region = "YourServiceRegion"
|
|
|
8 |
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
|
9 |
+
|
10 |
+
# Set up the audio configuration
|
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 |
+
)
|
19 |
+
pronunciation_config.enable_prosody_assessment()
|
20 |
|
21 |
+
# Create the recognizer
|
22 |
+
recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
|
23 |
+
pronunciation_config.apply_to(recognizer)
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
# Recognize speech and assess pronunciation
|
26 |
+
result = recognizer.recognize_once()
|
27 |
+
pronunciation_result = speechsdk.PronunciationAssessmentResult(result)
|
28 |
+
|
29 |
+
# Extract and format the results
|
30 |
+
accuracy_score = pronunciation_result.accuracy_score
|
31 |
+
fluency_score = pronunciation_result.fluency_score
|
32 |
+
completeness_score = pronunciation_result.completeness_score
|
33 |
+
prosody_score = pronunciation_result.prosody_score
|
34 |
|
35 |
+
return {
|
36 |
+
"Accuracy": accuracy_score,
|
37 |
+
"Fluency": fluency_score,
|
38 |
+
"Completeness": completeness_score,
|
39 |
+
"Prosody": prosody_score
|
40 |
+
}
|
41 |
|
42 |
+
# Create Gradio interface
|
43 |
+
interface = gr.Interface(
|
44 |
+
fn=assess_pronunciation,
|
45 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
46 |
+
outputs="json",
|
47 |
+
title="Chinese Pronunciation Checker"
|
48 |
+
)
|
49 |
|
50 |
+
if __name__ == "__main__":
|
51 |
+
interface.launch()
|