Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,25 +9,24 @@ import pandas as pd
|
|
9 |
# Sample dataframe with sentences
|
10 |
data = {
|
11 |
"Sentences": [
|
12 |
-
"
|
|
|
13 |
"To be or not to be, that is the question.",
|
14 |
-
"
|
15 |
-
"Hives give shelter to bees in large caves.",
|
16 |
-
"His decision to plant a rose was amazing.",
|
17 |
"She sells sea shells by the sea shore.",
|
18 |
-
"
|
19 |
-
"
|
20 |
"Good things come to those who wait.",
|
21 |
-
"
|
|
|
22 |
]
|
23 |
}
|
24 |
df = pd.DataFrame(data)
|
25 |
-
user_scores = {}
|
26 |
|
27 |
def transcribe_audio(file_info):
|
28 |
r = sr.Recognizer()
|
29 |
with tempfile.NamedTemporaryFile(delete=True, suffix=".wav") as tmpfile:
|
30 |
-
sf.write(tmpfile.name, data=file_info[1], samplerate=44100, format='WAV')
|
31 |
tmpfile.seek(0)
|
32 |
with sr.AudioFile(tmpfile.name) as source:
|
33 |
audio_data = r.record(source)
|
@@ -39,12 +38,36 @@ def transcribe_audio(file_info):
|
|
39 |
except sr.RequestError as e:
|
40 |
return f"Could not request results; {e}"
|
41 |
|
42 |
-
def pronunciation_correction(
|
|
|
43 |
user_spoken_text = transcribe_audio(file_info)
|
44 |
similarity = ratio(expected_text.lower(), user_spoken_text.lower())
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
48 |
else:
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Sample dataframe with sentences
|
10 |
data = {
|
11 |
"Sentences": [
|
12 |
+
"The quick brown fox jumps over the lazy dog.",
|
13 |
+
"An apple a day keeps the doctor away.",
|
14 |
"To be or not to be, that is the question.",
|
15 |
+
"All human beings are born free and equal in dignity and rights.",
|
|
|
|
|
16 |
"She sells sea shells by the sea shore.",
|
17 |
+
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
|
18 |
+
"A stitch in time saves nine.",
|
19 |
"Good things come to those who wait.",
|
20 |
+
"Time flies like an arrow; fruit flies like a banana.",
|
21 |
+
"You can't judge a book by its cover."
|
22 |
]
|
23 |
}
|
24 |
df = pd.DataFrame(data)
|
|
|
25 |
|
26 |
def transcribe_audio(file_info):
|
27 |
r = sr.Recognizer()
|
28 |
with tempfile.NamedTemporaryFile(delete=True, suffix=".wav") as tmpfile:
|
29 |
+
sf.write(file=tmpfile.name, data=file_info[1], samplerate=44100, format='WAV')
|
30 |
tmpfile.seek(0)
|
31 |
with sr.AudioFile(tmpfile.name) as source:
|
32 |
audio_data = r.record(source)
|
|
|
38 |
except sr.RequestError as e:
|
39 |
return f"Could not request results; {e}"
|
40 |
|
41 |
+
def pronunciation_correction(selected_sentence, file_info):
|
42 |
+
expected_text = selected_sentence
|
43 |
user_spoken_text = transcribe_audio(file_info)
|
44 |
similarity = ratio(expected_text.lower(), user_spoken_text.lower())
|
45 |
+
description = f"{similarity:.2f}" # Formats the float to 2 decimal places
|
46 |
+
|
47 |
+
if similarity >= 0.9:
|
48 |
+
feedback = "Excellent pronunciation!"
|
49 |
+
elif similarity >= 0.7:
|
50 |
+
feedback = "Good pronunciation!"
|
51 |
+
elif similarity >= 0.5:
|
52 |
+
feedback = "Needs improvement."
|
53 |
else:
|
54 |
+
feedback = "Poor pronunciation, try to focus more on clarity."
|
55 |
+
|
56 |
+
return feedback, description
|
57 |
+
|
58 |
+
|
59 |
+
iface = gr.Interface(
|
60 |
+
fn=pronunciation_correction,
|
61 |
+
inputs=[
|
62 |
+
gr.Dropdown(choices=df['Sentences'].tolist(), label="Select a Sentence"),
|
63 |
+
gr.Audio(label="Upload Audio File", type="numpy")
|
64 |
+
],
|
65 |
+
outputs=[
|
66 |
+
gr.Textbox(label="Pronunciation Feedback"), # Custom label for the text output
|
67 |
+
gr.Number(label="Pronunciation Accuracy Score: 0 (No Match) ~ 1 (Perfect)") # Custom label for the numerical output
|
68 |
+
],
|
69 |
+
title="π Pronunciation Feedback Tool"
|
70 |
+
)
|
71 |
+
|
72 |
+
|
73 |
+
iface.launch(debug=True)
|