RakanAlsheraiwi commited on
Commit
49cda4a
·
verified ·
1 Parent(s): 0ddcde3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -22
app.py CHANGED
@@ -2,35 +2,48 @@ import gradio as gr
2
  import difflib
3
  import random
4
 
5
- # Function to provide feedback without speech recognition
6
- def pronunciation_feedback(user_audio, language):
7
- # جملة لاختبار النطق (يمكن توليدها عشوائيًا)
8
- sentence = random.choice([
9
- "This is a simple test sentence.",
10
- "I would like to improve my pronunciation.",
11
- "Artificial intelligence is transforming the world.",
12
- "Gradio is a fantastic tool for machine learning applications."
13
- ]).lower()
14
-
15
- # تقديم ملاحظات بناءً على الجملة المثالية
16
- feedback = (
17
- "Great job! Your pronunciation is almost perfect!" if random.random() > 0.5
18
- else "Keep practicing! Try to mimic the pronunciation more closely."
19
- )
20
 
21
- # إعادة النص المثالي مع الملاحظات
22
- return f"Target Sentence: {sentence}\n\nFeedback: {feedback}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- # واجهة Gradio
25
  interface = gr.Interface(
26
- fn=pronunciation_feedback,
27
  inputs=[
28
  gr.Audio(type="filepath", label="Record your pronunciation"),
29
- gr.Dropdown(["en-US", "en-GB", "fr-FR", "es-ES"], label="Select Language", value="en-US")
30
  ],
31
  outputs="text",
32
- title="Smart Pronunciation Trainer",
33
- description="Record yourself pronouncing the given sentence in your selected language and receive feedback."
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()