Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import os
|
|
2 |
import gradio as gr
|
3 |
import openai
|
4 |
import speech_recognition as sr
|
5 |
-
import time
|
6 |
|
7 |
# Set OpenAI API key
|
8 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
@@ -38,27 +37,32 @@ def transcribe_audio_realtime(audio):
|
|
38 |
except sr.RequestError:
|
39 |
return "Could not request results from the speech recognition service"
|
40 |
|
41 |
-
def practice_pronunciation(audio):
|
42 |
-
|
|
|
43 |
transcription = transcribe_audio_realtime(audio)
|
44 |
-
feedback = get_pronunciation_feedback(
|
45 |
-
return
|
46 |
|
47 |
# Gradio interface
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
gr.
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
62 |
|
63 |
# Launch the app
|
64 |
if __name__ == "__main__":
|
|
|
2 |
import gradio as gr
|
3 |
import openai
|
4 |
import speech_recognition as sr
|
|
|
5 |
|
6 |
# Set OpenAI API key
|
7 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
|
|
37 |
except sr.RequestError:
|
38 |
return "Could not request results from the speech recognition service"
|
39 |
|
40 |
+
def practice_pronunciation(audio, text_to_read):
|
41 |
+
if not text_to_read:
|
42 |
+
text_to_read = generate_text()
|
43 |
transcription = transcribe_audio_realtime(audio)
|
44 |
+
feedback = get_pronunciation_feedback(text_to_read, transcription)
|
45 |
+
return text_to_read, transcription, feedback
|
46 |
|
47 |
# Gradio interface
|
48 |
+
with gr.Blocks() as demo:
|
49 |
+
gr.Markdown("# Pronunciation Practice Tool")
|
50 |
+
gr.Markdown("Generate a text to read, then record yourself reading it. The system will provide pronunciation feedback.")
|
51 |
+
|
52 |
+
with gr.Row():
|
53 |
+
text_to_read = gr.Textbox(label="Text to Read")
|
54 |
+
generate_button = gr.Button("Generate New Text")
|
55 |
+
|
56 |
+
audio_input = gr.Audio(type="filepath", label="Record your voice")
|
57 |
+
|
58 |
+
with gr.Row():
|
59 |
+
transcription_output = gr.Textbox(label="Your Transcription")
|
60 |
+
feedback_output = gr.Textbox(label="Pronunciation Feedback")
|
61 |
+
|
62 |
+
submit_button = gr.Button("Submit")
|
63 |
+
|
64 |
+
generate_button.click(generate_text, outputs=text_to_read)
|
65 |
+
submit_button.click(practice_pronunciation, inputs=[audio_input, text_to_read], outputs=[text_to_read, transcription_output, feedback_output])
|
66 |
|
67 |
# Launch the app
|
68 |
if __name__ == "__main__":
|