Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,11 +23,19 @@ def transcribe_audio(audio):
|
|
| 23 |
except sr.RequestError as e:
|
| 24 |
return f"Error with Google Speech Recognition service: {e}"
|
| 25 |
|
| 26 |
-
# Step 2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def compare_texts(reference_text, transcribed_text):
|
| 28 |
word_scores = []
|
| 29 |
reference_words = reference_text.split()
|
| 30 |
transcribed_words = transcribed_text.split()
|
|
|
|
| 31 |
|
| 32 |
sm = difflib.SequenceMatcher(None, reference_text, transcribed_text)
|
| 33 |
similarity_score = round(sm.ratio() * 100, 2)
|
|
@@ -46,13 +54,23 @@ def compare_texts(reference_text, transcribed_text):
|
|
| 46 |
elif difflib.get_close_matches(word, transcribed_words):
|
| 47 |
html_output += f'<span style="color: yellow;">{word}</span> ' # Close matches in yellow
|
| 48 |
else:
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
except IndexError:
|
| 51 |
html_output += f'<span style="color: red;">{word}</span> ' # Words in reference that were not transcribed
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
return html_output
|
| 54 |
|
| 55 |
-
# Step
|
| 56 |
def text_to_speech(paragraph):
|
| 57 |
tts = gTTS(paragraph)
|
| 58 |
tts.save("paragraph.mp3")
|
|
|
|
| 23 |
except sr.RequestError as e:
|
| 24 |
return f"Error with Google Speech Recognition service: {e}"
|
| 25 |
|
| 26 |
+
# Step 2: Create pronunciation audio for incorrect words
|
| 27 |
+
def create_pronunciation_audio(word):
|
| 28 |
+
tts = gTTS(word)
|
| 29 |
+
audio_filename = f"pronunciation_{word}.mp3"
|
| 30 |
+
tts.save(audio_filename)
|
| 31 |
+
return audio_filename
|
| 32 |
+
|
| 33 |
+
# Step 3: Compare the transcribed text with the input paragraph
|
| 34 |
def compare_texts(reference_text, transcribed_text):
|
| 35 |
word_scores = []
|
| 36 |
reference_words = reference_text.split()
|
| 37 |
transcribed_words = transcribed_text.split()
|
| 38 |
+
incorrect_words_audio_links = [] # Store audio links for incorrect words
|
| 39 |
|
| 40 |
sm = difflib.SequenceMatcher(None, reference_text, transcribed_text)
|
| 41 |
similarity_score = round(sm.ratio() * 100, 2)
|
|
|
|
| 54 |
elif difflib.get_close_matches(word, transcribed_words):
|
| 55 |
html_output += f'<span style="color: yellow;">{word}</span> ' # Close matches in yellow
|
| 56 |
else:
|
| 57 |
+
# Incorrect words in red
|
| 58 |
+
html_output += f'<span style="color: red;">{word}</span> '
|
| 59 |
+
# Create pronunciation audio for the incorrect word
|
| 60 |
+
audio_link = create_pronunciation_audio(word)
|
| 61 |
+
incorrect_words_audio_links.append(audio_link)
|
| 62 |
except IndexError:
|
| 63 |
html_output += f'<span style="color: red;">{word}</span> ' # Words in reference that were not transcribed
|
| 64 |
|
| 65 |
+
# Provide audio links for incorrect words
|
| 66 |
+
if incorrect_words_audio_links:
|
| 67 |
+
html_output += "<br><strong>Pronunciation for Incorrect Words:</strong><br>"
|
| 68 |
+
for audio in incorrect_words_audio_links:
|
| 69 |
+
html_output += f'<a href="{audio}" target="_blank">Listen</a><br>'
|
| 70 |
+
|
| 71 |
return html_output
|
| 72 |
|
| 73 |
+
# Step 4: Text-to-Speech Function
|
| 74 |
def text_to_speech(paragraph):
|
| 75 |
tts = gTTS(paragraph)
|
| 76 |
tts.save("paragraph.mp3")
|