AI-Edify commited on
Commit
371ca9c
·
verified ·
1 Parent(s): 112a3e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
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
- original_text = generate_text()
 
43
  transcription = transcribe_audio_realtime(audio)
44
- feedback = get_pronunciation_feedback(original_text, transcription)
45
- return original_text, transcription, feedback
46
 
47
  # Gradio interface
48
- demo = gr.Interface(
49
- fn=practice_pronunciation,
50
- inputs=[
51
- gr.Audio(type="filepath")
52
- ],
53
- outputs=[
54
- gr.Textbox(label="Text to Read"),
55
- gr.Textbox(label="Your Transcription"),
56
- gr.Textbox(label="Pronunciation Feedback")
57
- ],
58
- title="Pronunciation Practice Tool",
59
- description="Read the generated text aloud. The system will transcribe your speech and provide pronunciation feedback.",
60
- live=True
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__":