Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -46,13 +46,37 @@ def transcribe_audio(audio):
|
|
46 |
return f"Error with Google Speech Recognition service: {e}"
|
47 |
|
48 |
# Step 2: Create pronunciation audio for incorrect words
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
def create_pronunciation_audio(word):
|
50 |
time.sleep(1) # Chờ 5 giây
|
51 |
tts = gTTS(word)
|
52 |
main_url="https://mr2along-speech-recognize.hf.space/gradio_api/file="
|
|
|
53 |
audio_file_path = f"audio/{word}.mp3" # Save the audio to a file
|
54 |
tts.save(audio_file_path)
|
55 |
-
|
|
|
|
|
56 |
|
57 |
# Step 3: Compare the transcribed text with the input paragraph
|
58 |
def compare_texts(reference_text, transcribed_text):
|
@@ -100,7 +124,12 @@ def compare_texts(reference_text, transcribed_text):
|
|
100 |
# Provide audio for incorrect words
|
101 |
if incorrect_words_audios:
|
102 |
html_output += "<br><strong>Pronunciation for Incorrect Words:</strong><br>"
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
return [html_output, incorrect_words_audios]
|
106 |
|
|
|
46 |
return f"Error with Google Speech Recognition service: {e}"
|
47 |
|
48 |
# Step 2: Create pronunciation audio for incorrect words
|
49 |
+
def upfilepath(local_filename):
|
50 |
+
|
51 |
+
# URL để upload tệp âm thanh
|
52 |
+
upload_url = "https://mr2along-speech-recognize.hf.space/gradio_api/upload?upload_id=yw08d344te"
|
53 |
+
# Dữ liệu tệp cần upload
|
54 |
+
files = {'files': open(local_filename, 'rb')}
|
55 |
+
|
56 |
+
# Gửi yêu cầu POST
|
57 |
+
response = requests.post(upload_url, files=files)
|
58 |
+
|
59 |
+
# Kiểm tra kết quả trả về từ server
|
60 |
+
if response.status_code == 200:
|
61 |
+
print("Upload thành công!")
|
62 |
+
result=response.json()
|
63 |
+
extracted_path = result[0]
|
64 |
+
print(extracted_path) # In kết quả nếu server trả về dưới dạng JSON
|
65 |
+
return extracted_path
|
66 |
+
else:
|
67 |
+
print(f"Lỗi: {response.status_code}")
|
68 |
+
print(response.text) # In thông báo lỗi từ server
|
69 |
+
|
70 |
def create_pronunciation_audio(word):
|
71 |
time.sleep(1) # Chờ 5 giây
|
72 |
tts = gTTS(word)
|
73 |
main_url="https://mr2along-speech-recognize.hf.space/gradio_api/file="
|
74 |
+
|
75 |
audio_file_path = f"audio/{word}.mp3" # Save the audio to a file
|
76 |
tts.save(audio_file_path)
|
77 |
+
word_audio=upfilepath(audio_file_path)
|
78 |
+
print(f"Lỗi: {word_audio}")
|
79 |
+
return f"{main_url}/{word_audio}" # Return the file path of the saved audio
|
80 |
|
81 |
# Step 3: Compare the transcribed text with the input paragraph
|
82 |
def compare_texts(reference_text, transcribed_text):
|
|
|
124 |
# Provide audio for incorrect words
|
125 |
if incorrect_words_audios:
|
126 |
html_output += "<br><strong>Pronunciation for Incorrect Words:</strong><br>"
|
127 |
+
for word, audio in incorrect_words_audios:
|
128 |
+
suggestion = difflib.get_close_matches(word, reference_words, n=1)
|
129 |
+
suggestion_text = f" (Did you mean: <em>{suggestion[0]}</em>?)" if suggestion else ""
|
130 |
+
html_output += f'{word}: '
|
131 |
+
html_output += f'<audio controls><source src="{audio}" type="audio/wav">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
|
132 |
+
|
133 |
|
134 |
return [html_output, incorrect_words_audios]
|
135 |
|