Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,16 @@
|
|
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 = "
|
7 |
-
service_region = "
|
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 |
-
reference_text = "你好"
|
15 |
pronunciation_config = speechsdk.PronunciationAssessmentConfig(
|
16 |
reference_text=reference_text,
|
17 |
grading_system=speechsdk.PronunciationAssessmentGradingSystem.HundredMark,
|
@@ -46,7 +45,7 @@ def assess_pronunciation(audio_file):
|
|
46 |
}
|
47 |
elif result.reason == speechsdk.ResultReason.NoMatch:
|
48 |
print("NOMATCH: Speech could not be recognized.")
|
49 |
-
return {"Error": "
|
50 |
elif result.reason == speechsdk.ResultReason.Canceled:
|
51 |
cancellation_details = speechsdk.CancellationDetails(result)
|
52 |
print(f"CANCELED: Reason={cancellation_details.reason}")
|
@@ -59,7 +58,10 @@ def assess_pronunciation(audio_file):
|
|
59 |
# Create Gradio interface
|
60 |
interface = gr.Interface(
|
61 |
fn=assess_pronunciation,
|
62 |
-
inputs=
|
|
|
|
|
|
|
63 |
outputs="json",
|
64 |
title="Chinese Pronunciation Checker"
|
65 |
)
|
|
|
1 |
import gradio as gr
|
2 |
import azure.cognitiveservices.speech as speechsdk
|
3 |
|
4 |
+
def assess_pronunciation(audio_file, reference_text):
|
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=reference_text,
|
16 |
grading_system=speechsdk.PronunciationAssessmentGradingSystem.HundredMark,
|
|
|
45 |
}
|
46 |
elif result.reason == speechsdk.ResultReason.NoMatch:
|
47 |
print("NOMATCH: Speech could not be recognized.")
|
48 |
+
return {"Error": "Speech could not be recognized. Please try again with a clearer audio."}
|
49 |
elif result.reason == speechsdk.ResultReason.Canceled:
|
50 |
cancellation_details = speechsdk.CancellationDetails(result)
|
51 |
print(f"CANCELED: Reason={cancellation_details.reason}")
|
|
|
58 |
# Create Gradio interface
|
59 |
interface = gr.Interface(
|
60 |
fn=assess_pronunciation,
|
61 |
+
inputs=[
|
62 |
+
gr.Audio(type="filepath"), # Audio input
|
63 |
+
gr.Textbox(label="Reference Text", placeholder="Enter the reference text you are pronouncing") # Reference text input
|
64 |
+
],
|
65 |
outputs="json",
|
66 |
title="Chinese Pronunciation Checker"
|
67 |
)
|