File size: 2,270 Bytes
77efc67
 
938d676
77efc67
f294699
49cda4a
 
 
 
 
 
 
 
 
 
 
 
 
 
938d676
f294699
 
 
34da04b
 
49cda4a
 
 
 
 
 
 
 
 
 
 
 
f294699
 
77efc67
2a3c603
77efc67
49cda4a
77efc67
2551a01
34da04b
8af790c
f294699
 
34da04b
 
 
77efc67
49cda4a
f294699
77efc67
 
 
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
import gradio as gr
import difflib
import random

# Function to evaluate the pronunciation and get a new sentence
def pronunciation_evaluator(user_audio, sentence):
    # Mock text (assuming perfect recognition for the example)
    recognized_text = sentence.lower()  # In a real application, this would be the result of speech-to-text
    
    # Compare the user's pronunciation with the original sentence
    similarity_ratio = difflib.SequenceMatcher(None, recognized_text, sentence.lower()).ratio()
    
    # Generate feedback based on similarity
    if similarity_ratio > 0.9:
        feedback = "Excellent! Your pronunciation is very accurate."
    elif similarity_ratio > 0.7:
        feedback = "Good job! But there's some room for improvement."
    else:
        feedback = "Keep practicing! Try to match the pronunciation more closely."
    
    # Get a new sentence for the next round
    new_sentence = get_sentence()
    
    # Return the feedback and the new sentence for the next round
    return feedback, new_sentence

# Function to get a random sentence
def get_sentence():
    sentences = [
        "The quick brown fox jumps over the lazy dog.",
        "She sells seashells by the seashore.",
        "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
        "Peter Piper picked a peck of pickled peppers.",
        "I scream, you scream, we all scream for ice cream."
    ]
    return random.choice(sentences)

# Initial sentence
initial_sentence = get_sentence()

# Gradio Interface
interface = gr.Interface(
    fn=pronunciation_evaluator,
    inputs=[
        gr.Audio(type="filepath", label="Record your pronunciation"),
        gr.Textbox(lines=2, label="Sentence to Pronounce", value=initial_sentence, interactive=False),
        gr.State(value=initial_sentence)  # Holds the current sentence
    ],
    outputs=[
        "text",  # Feedback on pronunciation
        gr.Textbox(label="Next Sentence to Pronounce", interactive=False),  # Display the new sentence
        gr.State()  # State for the next input
    ],
    title="Pronunciation Evaluator",
    description="Record yourself pronouncing the given sentence and receive feedback. A new sentence will be provided after each evaluation."
)

interface.launch()