Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from gtts import gTTS
|
|
7 |
import io
|
8 |
from pydub import AudioSegment
|
9 |
import time
|
10 |
-
import
|
11 |
|
12 |
# Create audio directory if it doesn't exist
|
13 |
if not os.path.exists('audio'):
|
@@ -78,7 +78,22 @@ def create_pronunciation_audio(word):
|
|
78 |
except Exception as e:
|
79 |
return f"Failed to create pronunciation audio: {e}"
|
80 |
|
81 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
def compare_texts(reference_text, transcribed_text):
|
83 |
reference_words = reference_text.split()
|
84 |
transcribed_words = transcribed_text.split()
|
@@ -101,9 +116,9 @@ def compare_texts(reference_text, transcribed_text):
|
|
101 |
html_output += f"<strong>Quality Score:</strong> {similarity_score}%<br>"
|
102 |
html_output += f"<strong>Transcribed Text:</strong> {transcribed_text}<br>"
|
103 |
|
104 |
-
# Add phonetic
|
105 |
-
phonetic_transcription = " ".join([
|
106 |
-
html_output += f"<strong>Phonetic
|
107 |
|
108 |
html_output += "<strong>Word Score List:</strong><br>"
|
109 |
|
@@ -135,7 +150,7 @@ def compare_texts(reference_text, transcribed_text):
|
|
135 |
html_output += f'{word}: '
|
136 |
html_output += f'<audio controls><source src="{audio_src}" type="audio/mpeg">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
|
137 |
|
138 |
-
# Return the final result with phonetic
|
139 |
return [html_output]
|
140 |
|
141 |
# Step 4: Text-to-Speech Function
|
|
|
7 |
import io
|
8 |
from pydub import AudioSegment
|
9 |
import time
|
10 |
+
import re
|
11 |
|
12 |
# Create audio directory if it doesn't exist
|
13 |
if not os.path.exists('audio'):
|
|
|
78 |
except Exception as e:
|
79 |
return f"Failed to create pronunciation audio: {e}"
|
80 |
|
81 |
+
# Function to respell words phonetically
|
82 |
+
def phonetic_respelling(word):
|
83 |
+
word = word.lower()
|
84 |
+
respelling = word
|
85 |
+
# Simplified phonetic transformations
|
86 |
+
respelling = re.sub(r'th', 'th', respelling) # 'th' as in 'the'
|
87 |
+
respelling = re.sub(r'[aeiou]', lambda m: f'{m.group(0)}', respelling) # Simplify vowels
|
88 |
+
respelling = re.sub(r'c', 'k', respelling) # 'c' sounds like 'k'
|
89 |
+
respelling = re.sub(r'ph', 'f', respelling) # 'ph' as 'f'
|
90 |
+
respelling = re.sub(r'ch', 'ch', respelling) # 'ch' as in 'church'
|
91 |
+
respelling = re.sub(r'qu', 'kw', respelling) # 'qu' as 'kw'
|
92 |
+
respelling = re.sub(r'sh', 'sh', respelling) # 'sh' as in 'shoe'
|
93 |
+
respelling = re.sub(r'[^a-z]', '', respelling) # Remove non-alphabet characters
|
94 |
+
return respelling
|
95 |
+
|
96 |
+
# Step 3: Compare the transcribed text with the input paragraph and add phonetic respelling
|
97 |
def compare_texts(reference_text, transcribed_text):
|
98 |
reference_words = reference_text.split()
|
99 |
transcribed_words = transcribed_text.split()
|
|
|
116 |
html_output += f"<strong>Quality Score:</strong> {similarity_score}%<br>"
|
117 |
html_output += f"<strong>Transcribed Text:</strong> {transcribed_text}<br>"
|
118 |
|
119 |
+
# Add phonetic respelling for the entire sentence
|
120 |
+
phonetic_transcription = " ".join([phonetic_respelling(word) for word in transcribed_words])
|
121 |
+
html_output += f"<strong>Phonetic Respelling:</strong> {phonetic_transcription}<br>"
|
122 |
|
123 |
html_output += "<strong>Word Score List:</strong><br>"
|
124 |
|
|
|
150 |
html_output += f'{word}: '
|
151 |
html_output += f'<audio controls><source src="{audio_src}" type="audio/mpeg">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
|
152 |
|
153 |
+
# Return the final result with phonetic respelling
|
154 |
return [html_output]
|
155 |
|
156 |
# Step 4: Text-to-Speech Function
|