Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,10 @@ if not os.path.exists('audio'):
|
|
15 |
os.makedirs('audio')
|
16 |
|
17 |
# Initialize the epitran object for English
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
# Step 1: Transcribe the audio file
|
21 |
def transcribe_audio(audio):
|
@@ -51,7 +54,7 @@ def transcribe_audio(audio):
|
|
51 |
except sr.RequestError as e:
|
52 |
return f"Error with Google Speech Recognition service: {e}"
|
53 |
|
54 |
-
#
|
55 |
def create_pronunciation_audio(word):
|
56 |
try:
|
57 |
tts = gTTS(word)
|
@@ -87,9 +90,13 @@ def phonetic_respelling(sentence):
|
|
87 |
|
88 |
# Function for IPA transcription
|
89 |
def ipa_transcription(sentence):
|
90 |
-
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
# Step
|
93 |
def compare_texts(reference_text, transcribed_text):
|
94 |
reference_words = reference_text.split()
|
95 |
transcribed_words = transcribed_text.split()
|
@@ -140,16 +147,13 @@ def compare_texts(reference_text, transcribed_text):
|
|
140 |
suggestion = difflib.get_close_matches(word, reference_words, n=1)
|
141 |
suggestion_text = f" (Did you mean: <em>{suggestion[0]}</em>?)" if suggestion else ""
|
142 |
up_audio = upfilepath(audio)
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
html_output += f'<audio controls><source src="{audio_src}" type="audio/mpeg">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
|
147 |
-
else:
|
148 |
-
html_output += f'{word}: <span style="color: red;">Audio not available.</span><br>'
|
149 |
|
150 |
return [html_output]
|
151 |
|
152 |
-
# Step
|
153 |
def text_to_speech(paragraph):
|
154 |
if not paragraph:
|
155 |
return None # Handle the case when no text is provided
|
@@ -168,7 +172,7 @@ def gradio_function(paragraph, audio):
|
|
168 |
|
169 |
# Return comparison result
|
170 |
return comparison_result
|
171 |
-
|
172 |
# Gradio Interface using the updated API
|
173 |
interface = gr.Interface(
|
174 |
fn=gradio_function,
|
|
|
15 |
os.makedirs('audio')
|
16 |
|
17 |
# Initialize the epitran object for English
|
18 |
+
try:
|
19 |
+
epi = epitran.Epitran('eng-Latn')
|
20 |
+
except Exception as e:
|
21 |
+
print(f"Error initializing Epitran: {e}")
|
22 |
|
23 |
# Step 1: Transcribe the audio file
|
24 |
def transcribe_audio(audio):
|
|
|
54 |
except sr.RequestError as e:
|
55 |
return f"Error with Google Speech Recognition service: {e}"
|
56 |
|
57 |
+
# Step 2: Create pronunciation audio for incorrect words (locally)
|
58 |
def create_pronunciation_audio(word):
|
59 |
try:
|
60 |
tts = gTTS(word)
|
|
|
90 |
|
91 |
# Function for IPA transcription
|
92 |
def ipa_transcription(sentence):
|
93 |
+
try:
|
94 |
+
return epi.transliterate(sentence)
|
95 |
+
except Exception as e:
|
96 |
+
print(f"Error during IPA transcription: {e}")
|
97 |
+
return "IPA transcription failed."
|
98 |
|
99 |
+
# Step 3: Compare the transcribed text with the input paragraph
|
100 |
def compare_texts(reference_text, transcribed_text):
|
101 |
reference_words = reference_text.split()
|
102 |
transcribed_words = transcribed_text.split()
|
|
|
147 |
suggestion = difflib.get_close_matches(word, reference_words, n=1)
|
148 |
suggestion_text = f" (Did you mean: <em>{suggestion[0]}</em>?)" if suggestion else ""
|
149 |
up_audio = upfilepath(audio)
|
150 |
+
audio_src = f"https://mr2along-speech-recognize.hf.space/gradio_api/file={up_audio}"
|
151 |
+
html_output += f'{word}: '
|
152 |
+
html_output += f'<audio controls><source src="{audio_src}" type="audio/mpeg">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
|
|
|
|
|
|
|
153 |
|
154 |
return [html_output]
|
155 |
|
156 |
+
# Step 4: Text-to-Speech Function
|
157 |
def text_to_speech(paragraph):
|
158 |
if not paragraph:
|
159 |
return None # Handle the case when no text is provided
|
|
|
172 |
|
173 |
# Return comparison result
|
174 |
return comparison_result
|
175 |
+
|
176 |
# Gradio Interface using the updated API
|
177 |
interface = gr.Interface(
|
178 |
fn=gradio_function,
|