File size: 2,874 Bytes
505b951
8626f14
 
 
 
 
505b951
8626f14
505b951
 
 
 
 
 
 
 
 
8626f14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
505b951
8626f14
 
 
 
505b951
8626f14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import gradio as gr
from llm import get_llm_feedback
from asr_api import transcribe_with_openrouter
from user_data import load_user_data, save_user_data
from phonetics import analyze_audio_phonetically, extract_phonemes

# Example minimal Gradio app setup:
PRACTICE_EXERCISES = [
    {"title": "Basic Vowels", "text": "The cat sat on the mat."},
    {"title": "R Sound", "text": "The red robin ran around the river."},
    {"title": "TH Sounds", "text": "I think these three things are worth it."},
    {"title": "L vs R", "text": "The light rain falls along the lake."},
    {"title": "V vs W", "text": "We very much want to visit the west village."},
    {"title": "Short Phrases", "text": "Excuse me. Thank you. I'm sorry. Nice to meet you."}
]

def process_audio(audio, ref_text):
    if not audio:
        return "No audio recorded", "Please record your pronunciation first."
    feedback, transcription = get_llm_feedback(audio, None, ref_text, transcribe_func=transcribe_with_openrouter)
    return transcription, feedback

def main():
    with gr.Blocks(title="ESL Pronunciation Coach - Advanced") as demo:
        user_id = gr.State("default")
        gr.Markdown("# 🗣️ Advanced Pronunciation Coach")
        with gr.Tab("Practice"):
            with gr.Row():
                with gr.Column(scale=2):
                    exercise_dropdown = gr.Dropdown(
                        choices=[ex["title"] for ex in PRACTICE_EXERCISES],
                        label="Select Practice Exercise",
                        value=PRACTICE_EXERCISES[0]["title"]
                    )
                    reference_text = gr.Textbox(
                        label="Practice Text (Read This Aloud)",
                        value=PRACTICE_EXERCISES[0]["text"],
                        lines=2
                    )
                    def update_reference_text(exercise_title):
                        for ex in PRACTICE_EXERCISES:
                            if ex["title"] == exercise_title:
                                return ex["text"]
                        return ""
                    exercise_dropdown.change(update_reference_text, exercise_dropdown, reference_text)
                    audio_input = gr.Audio(label="Record your pronunciation", type="filepath", format="wav", show_label=True)
                    submit_btn = gr.Button("Get Feedback", variant="primary")
                with gr.Column(scale=3):
                    transcription_output = gr.Textbox(label="Your Speech (Transcribed)", lines=2)
                    feedback_output = gr.Textbox(label="Pronunciation Feedback", lines=6)
            submit_btn.click(
                process_audio,
                inputs=[audio_input, reference_text],
                outputs=[transcription_output, feedback_output]
            )
    demo.launch()

if __name__ == "__main__":
    main()