Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,40 +10,6 @@ import time
|
|
10 |
# Create audio directory if it doesn't exist
|
11 |
if not os.path.exists('audio'):
|
12 |
os.makedirs('audio')
|
13 |
-
filePath=""
|
14 |
-
def upfilepath():
|
15 |
-
# URL của tệp âm thanh (nguồn từ internet)
|
16 |
-
file_url = "https://st.ielts-fighter.com/src/ielts-fighter/2019/09/09/i%20ng%E1%BA%AFn.mp3"
|
17 |
-
|
18 |
-
# URL để upload tệp âm thanh
|
19 |
-
upload_url = "https://mr2along-speech-recognize.hf.space/gradio_api/upload?upload_id=yw08d344te"
|
20 |
-
|
21 |
-
# Tải tệp âm thanh từ link
|
22 |
-
response = requests.get(file_url)
|
23 |
-
|
24 |
-
# Kiểm tra xem tải tệp thành công hay không
|
25 |
-
if response.status_code == 200:
|
26 |
-
# Lưu tệp vào bộ nhớ tạm thời
|
27 |
-
local_filename = "temp_audio_file.mp3"
|
28 |
-
with open(local_filename, 'wb') as f:
|
29 |
-
f.write(response.content)
|
30 |
-
|
31 |
-
# Dữ liệu tệp cần upload
|
32 |
-
files = {'files': open(local_filename, 'rb')}
|
33 |
-
|
34 |
-
# Gửi yêu cầu POST
|
35 |
-
response = requests.post(upload_url, files=files)
|
36 |
-
|
37 |
-
# Kiểm tra kết quả trả về từ server
|
38 |
-
if response.status_code == 200:
|
39 |
-
print("Upload thành công!")
|
40 |
-
result=response.json()
|
41 |
-
extracted_path = os.path.dirname(result[0])
|
42 |
-
print(extracted_path) # In kết quả nếu server trả về dưới dạng JSON
|
43 |
-
return extracted_path
|
44 |
-
else:
|
45 |
-
print(f"Lỗi: {response.status_code}")
|
46 |
-
print(response.text) # In thông báo lỗi từ server
|
47 |
|
48 |
# Step 1: Transcribe the audio file
|
49 |
def transcribe_audio(audio):
|
@@ -130,7 +96,7 @@ def compare_texts(reference_text, transcribed_text):
|
|
130 |
html_output += f'<audio controls><source src="{audio}" type="audio/mpeg">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
|
131 |
|
132 |
|
133 |
-
return html_output
|
134 |
|
135 |
# Step 4: Text-to-Speech Function
|
136 |
def text_to_speech(paragraph):
|
@@ -145,9 +111,7 @@ def text_to_speech(paragraph):
|
|
145 |
# Gradio Interface Function
|
146 |
def gradio_function(paragraph, audio):
|
147 |
# Transcribe the audio
|
148 |
-
filePath=upfilepath()
|
149 |
transcribed_text = transcribe_audio(audio)
|
150 |
-
|
151 |
# Compare the original paragraph with the transcribed text
|
152 |
comparison_result = compare_texts(paragraph, transcribed_text)
|
153 |
|
@@ -161,7 +125,7 @@ interface = gr.Interface(
|
|
161 |
gr.Textbox(lines=5, label="Input Paragraph"),
|
162 |
gr.Audio(type="filepath", label="Record Audio")
|
163 |
],
|
164 |
-
outputs="html",
|
165 |
title="Speech Recognition Comparison",
|
166 |
description="Input a paragraph, record your audio, and compare the transcription to the original text."
|
167 |
)
|
|
|
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):
|
|
|
96 |
html_output += f'<audio controls><source src="{audio}" type="audio/mpeg">Your browser does not support the audio tag.</audio>{suggestion_text}<br>'
|
97 |
|
98 |
|
99 |
+
return [html_output, incorrect_words_audios]
|
100 |
|
101 |
# Step 4: Text-to-Speech Function
|
102 |
def text_to_speech(paragraph):
|
|
|
111 |
# Gradio Interface Function
|
112 |
def gradio_function(paragraph, audio):
|
113 |
# Transcribe the audio
|
|
|
114 |
transcribed_text = transcribe_audio(audio)
|
|
|
115 |
# Compare the original paragraph with the transcribed text
|
116 |
comparison_result = compare_texts(paragraph, transcribed_text)
|
117 |
|
|
|
125 |
gr.Textbox(lines=5, label="Input Paragraph"),
|
126 |
gr.Audio(type="filepath", label="Record Audio")
|
127 |
],
|
128 |
+
outputs=["html","audio"],
|
129 |
title="Speech Recognition Comparison",
|
130 |
description="Input a paragraph, record your audio, and compare the transcription to the original text."
|
131 |
)
|