aikitty commited on
Commit
b8a29bf
·
verified ·
1 Parent(s): 08f6846

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -25
app.py CHANGED
@@ -1,33 +1,51 @@
1
- import streamlit as st
2
  import azure.cognitiveservices.speech as speechsdk
3
 
4
- # Azure Speech Service credentials
5
- speech_key = "12afe22c558a4f8d8bd28d6a67cdb9b0"
6
- service_region = "westus"
7
-
8
- def transcribe_audio(file_path):
9
  speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
10
- audio_input = speechsdk.AudioConfig(filename=file_path)
11
- speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_input)
 
 
 
 
 
 
 
 
 
12
 
13
- result = speech_recognizer.recognize_once()
14
- if result.reason == speechsdk.ResultReason.RecognizedSpeech:
15
- return result.text
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
- st.title("Chinese Pronunciation Checker")
 
 
 
 
 
 
 
 
22
 
23
- uploaded_file = st.file_uploader("Choose an audio file", type=["wav", "mp3"])
 
 
 
 
 
24
 
25
- if uploaded_file is not None:
26
- st.audio(uploaded_file, format="audio/wav")
27
- file_path = f"temp_audio.{uploaded_file.type.split('/')[-1]}"
28
-
29
- with open(file_path, "wb") as f:
30
- f.write(uploaded_file.getbuffer())
 
31
 
32
- transcript = transcribe_audio(file_path)
33
- st.write("Transcribed Text: ", transcript)
 
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()