Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import difflib
|
3 |
+
|
4 |
+
# Function to simulate pronunciation feedback
|
5 |
+
def pronunciation_feedback(user_audio, sentence):
|
6 |
+
# Simulate a correct pronunciation for the given sentence
|
7 |
+
correct_text = sentence.lower()
|
8 |
+
|
9 |
+
# Convert audio to text using speech recognition (mocking this part for the example)
|
10 |
+
user_text = "This is a sample text." # Replace with actual speech recognition result
|
11 |
+
|
12 |
+
# Compare the user's text with the correct text
|
13 |
+
ratio = difflib.SequenceMatcher(None, correct_text, user_text.lower()).ratio()
|
14 |
+
|
15 |
+
# Generate feedback based on similarity
|
16 |
+
if ratio > 0.9:
|
17 |
+
feedback = "Great job! Your pronunciation is almost perfect!"
|
18 |
+
elif ratio > 0.7:
|
19 |
+
feedback = "Good job! But you can improve your pronunciation on some words."
|
20 |
+
else:
|
21 |
+
feedback = "Keep practicing! Try to mimic the pronunciation more closely."
|
22 |
+
|
23 |
+
return feedback
|
24 |
+
|
25 |
+
# Gradio Interface
|
26 |
+
interface = gr.Interface(
|
27 |
+
fn=pronunciation_feedback,
|
28 |
+
inputs=[
|
29 |
+
gr.Audio(source="microphone", type="filepath", label="Record your pronunciation"),
|
30 |
+
gr.Textbox(lines=2, label="Sentence to pronounce", value="This is a sample text.")
|
31 |
+
],
|
32 |
+
outputs="text",
|
33 |
+
title="Pronunciation Trainer",
|
34 |
+
description="Record yourself pronouncing the given sentence and receive feedback on your pronunciation."
|
35 |
+
)
|
36 |
+
|
37 |
+
interface.launch()
|