|
import gradio as gr |
|
import difflib |
|
import random |
|
|
|
|
|
def pronunciation_evaluator(user_audio, sentence): |
|
|
|
recognized_text = sentence.lower() |
|
|
|
|
|
similarity_ratio = difflib.SequenceMatcher(None, recognized_text, sentence.lower()).ratio() |
|
|
|
|
|
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." |
|
|
|
|
|
new_sentence = get_sentence() |
|
|
|
|
|
return f"Recognized Text: {recognized_text}\n\nFeedback: {feedback}", new_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 = get_sentence() |
|
|
|
|
|
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) |
|
], |
|
outputs=[ |
|
"text", |
|
gr.Textbox(label="New Sentence to Pronounce", interactive=False), |
|
gr.State() |
|
], |
|
title="Pronunciation Evaluator", |
|
description="Record yourself pronouncing the given sentence and receive feedback. A new sentence will be provided after each evaluation." |
|
) |
|
|
|
interface.launch() |
|
|