Update app.py
Browse files
app.py
CHANGED
@@ -2,35 +2,48 @@ import gradio as gr
|
|
2 |
import difflib
|
3 |
import random
|
4 |
|
5 |
-
# Function to
|
6 |
-
def
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
"
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
#
|
22 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
# واجهة Gradio
|
25 |
interface = gr.Interface(
|
26 |
-
fn=
|
27 |
inputs=[
|
28 |
gr.Audio(type="filepath", label="Record your pronunciation"),
|
29 |
-
gr.
|
30 |
],
|
31 |
outputs="text",
|
32 |
-
title="
|
33 |
-
description="Record yourself pronouncing the given sentence
|
34 |
)
|
35 |
|
36 |
interface.launch()
|
|
|
2 |
import difflib
|
3 |
import random
|
4 |
|
5 |
+
# Function to evaluate the pronunciation
|
6 |
+
def pronunciation_evaluator(user_audio, sentence):
|
7 |
+
# Mock text (assuming perfect recognition for the example)
|
8 |
+
recognized_text = sentence.lower() # In a real application, this would be the result of speech-to-text
|
9 |
+
|
10 |
+
# Compare the user's pronunciation with the original sentence
|
11 |
+
similarity_ratio = difflib.SequenceMatcher(None, recognized_text, sentence.lower()).ratio()
|
12 |
+
|
13 |
+
# Generate feedback based on similarity
|
14 |
+
if similarity_ratio > 0.9:
|
15 |
+
feedback = "Excellent! Your pronunciation is very accurate."
|
16 |
+
elif similarity_ratio > 0.7:
|
17 |
+
feedback = "Good job! But there's some room for improvement."
|
18 |
+
else:
|
19 |
+
feedback = "Keep practicing! Try to match the pronunciation more closely."
|
20 |
|
21 |
+
# Return the original sentence and feedback
|
22 |
+
return f"Recognized Text: {recognized_text}\n\nFeedback: {feedback}"
|
23 |
+
|
24 |
+
# Function to get a random sentence
|
25 |
+
def get_sentence():
|
26 |
+
sentences = [
|
27 |
+
"The quick brown fox jumps over the lazy dog.",
|
28 |
+
"She sells seashells by the seashore.",
|
29 |
+
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
|
30 |
+
"Peter Piper picked a peck of pickled peppers.",
|
31 |
+
"I scream, you scream, we all scream for ice cream."
|
32 |
+
]
|
33 |
+
return random.choice(sentences)
|
34 |
+
|
35 |
+
# Gradio Interface
|
36 |
+
sentence = get_sentence()
|
37 |
|
|
|
38 |
interface = gr.Interface(
|
39 |
+
fn=pronunciation_evaluator,
|
40 |
inputs=[
|
41 |
gr.Audio(type="filepath", label="Record your pronunciation"),
|
42 |
+
gr.Textbox(lines=2, label="Sentence to pronounce", value=sentence, readonly=True)
|
43 |
],
|
44 |
outputs="text",
|
45 |
+
title="Pronunciation Evaluator",
|
46 |
+
description="Record yourself pronouncing the given sentence and receive feedback on your pronunciation."
|
47 |
)
|
48 |
|
49 |
interface.launch()
|