Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,26 @@ import time
|
|
10 |
# Create audio directory if it doesn't exist
|
11 |
if not os.path.exists('audio'):
|
12 |
os.makedirs('audio')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Step 1: Transcribe the audio file
|
15 |
def transcribe_audio(audio):
|
@@ -102,8 +122,10 @@ def compare_texts(reference_text, transcribed_text):
|
|
102 |
for word, audio in incorrect_words_audios:
|
103 |
suggestion = difflib.get_close_matches(word, reference_words, n=1)
|
104 |
suggestion_text = f" (Did you mean: <em>{suggestion[0]}</em>?)" if suggestion else ""
|
|
|
|
|
105 |
html_output += f'{word}: '
|
106 |
-
html_output += f'<audio controls><source src="{
|
107 |
|
108 |
return [html_output, [audio for _, audio in incorrect_words_audios]]
|
109 |
|
|
|
10 |
# Create audio directory if it doesn't exist
|
11 |
if not os.path.exists('audio'):
|
12 |
os.makedirs('audio')
|
13 |
+
# Step 2: Create pronunciation audio for incorrect words
|
14 |
+
def upfilepath(local_filename):
|
15 |
+
ts = time.time()
|
16 |
+
upload_url = f"https://mr2along-speech-recognize.hf.space/gradio_api/upload?upload_id={ts}"
|
17 |
+
files = {'files': open(local_filename, 'rb')}
|
18 |
+
|
19 |
+
try:
|
20 |
+
response = requests.post(upload_url, files=files, timeout=30) # Set timeout (e.g., 30 seconds)
|
21 |
+
|
22 |
+
if response.status_code == 200:
|
23 |
+
result = response.json()
|
24 |
+
extracted_path = result[0]
|
25 |
+
return extracted_path
|
26 |
+
else:
|
27 |
+
return None
|
28 |
+
|
29 |
+
except requests.exceptions.Timeout:
|
30 |
+
return "Request timed out. Please try again."
|
31 |
+
except Exception as e:
|
32 |
+
return f"An error occurred: {e}"
|
33 |
|
34 |
# Step 1: Transcribe the audio file
|
35 |
def transcribe_audio(audio):
|
|
|
122 |
for word, audio in incorrect_words_audios:
|
123 |
suggestion = difflib.get_close_matches(word, reference_words, n=1)
|
124 |
suggestion_text = f" (Did you mean: <em>{suggestion[0]}</em>?)" if suggestion else ""
|
125 |
+
up_audio=upfilepath(audio)
|
126 |
+
audio_src=f"https://mr2along-speech-recognize.hf.space/gradio_api/file={up_audio}"
|
127 |
html_output += f'{word}: '
|
128 |
+
html_output += f'<audio controls><source src="{audio_src}" type="audio/mpeg">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
|
129 |
|
130 |
return [html_output, [audio for _, audio in incorrect_words_audios]]
|
131 |
|