Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import whisper
|
|
|
|
| 3 |
|
| 4 |
# Load the Whisper model
|
| 5 |
model = whisper.load_model("base")
|
| 6 |
|
| 7 |
-
def
|
| 8 |
"""
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
"""
|
| 11 |
# Transcribe the audio using Whisper
|
| 12 |
result = model.transcribe(audio)
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
# Create the Gradio interface for real-time transcription
|
| 16 |
interface = gr.Interface(
|
| 17 |
-
fn=
|
| 18 |
-
inputs=gr.Audio(source="microphone", type="filepath"),
|
| 19 |
-
outputs="
|
| 20 |
live=True # Enables real-time transcription
|
| 21 |
)
|
| 22 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import whisper
|
| 3 |
+
import difflib # To compare expected vs actual pronunciation
|
| 4 |
|
| 5 |
# Load the Whisper model
|
| 6 |
model = whisper.load_model("base")
|
| 7 |
|
| 8 |
+
def pronunciation_feedback(transcription, reference_text):
|
| 9 |
"""
|
| 10 |
+
Function to give basic feedback on pronunciation based on differences
|
| 11 |
+
between the transcribed text and the reference text.
|
| 12 |
+
"""
|
| 13 |
+
diff = difflib.ndiff(reference_text.split(), transcription.split())
|
| 14 |
+
errors = [word for word in diff if word.startswith('- ')] # Find words missing or mispronounced
|
| 15 |
+
if errors:
|
| 16 |
+
feedback = "You mispronounced the following words: " + ', '.join([error[2:] for error in errors])
|
| 17 |
+
else:
|
| 18 |
+
feedback = "Great job! Your pronunciation is spot on."
|
| 19 |
+
return feedback
|
| 20 |
+
|
| 21 |
+
def transcribe_and_feedback(audio, reference_text):
|
| 22 |
+
"""
|
| 23 |
+
Transcribes audio and provides pronunciation feedback.
|
| 24 |
"""
|
| 25 |
# Transcribe the audio using Whisper
|
| 26 |
result = model.transcribe(audio)
|
| 27 |
+
transcription = result['text']
|
| 28 |
+
|
| 29 |
+
# Provide basic pronunciation feedback
|
| 30 |
+
feedback = pronunciation_feedback(transcription, reference_text)
|
| 31 |
+
|
| 32 |
+
return transcription, feedback
|
| 33 |
|
| 34 |
+
# Create the Gradio interface for real-time transcription and feedback
|
| 35 |
interface = gr.Interface(
|
| 36 |
+
fn=transcribe_and_feedback, # Function to transcribe and give feedback
|
| 37 |
+
inputs=[gr.Audio(source="microphone", type="filepath"), gr.Textbox(label="Expected Text")],
|
| 38 |
+
outputs=[gr.Textbox(label="Transcription"), gr.Textbox(label="Pronunciation Feedback")],
|
| 39 |
live=True # Enables real-time transcription
|
| 40 |
)
|
| 41 |
|