Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -29,15 +29,11 @@ def load_image(image_path):
|
|
29 |
image = PIL.Image.open(image_path)
|
30 |
return image
|
31 |
|
32 |
-
def
|
33 |
-
"""Convert text to speech and
|
34 |
tts = gTTS(text=text, lang='en')
|
35 |
-
tts.save(
|
36 |
-
|
37 |
-
audio_bytes = audio_file.read()
|
38 |
-
st.audio(audio_bytes, format="audio/mp3")
|
39 |
-
audio_file.close()
|
40 |
-
os.remove("detected_braille.mp3") # 删除文件,节省空间
|
41 |
|
42 |
# title
|
43 |
st.title("Braille Pattern Detection")
|
@@ -114,16 +110,16 @@ try:
|
|
114 |
st.write(str_left_to_right)
|
115 |
|
116 |
# Convert detected Braille text to audio and play
|
117 |
-
|
118 |
-
|
119 |
|
120 |
except Exception as ex:
|
121 |
st.write("Please try again with images with types of JPG, JPEG, PNG ...")
|
122 |
|
123 |
-
with open(
|
124 |
st.download_button(
|
125 |
-
"Download
|
126 |
data=fl,
|
127 |
-
file_name="
|
128 |
-
mime="
|
129 |
)
|
|
|
29 |
image = PIL.Image.open(image_path)
|
30 |
return image
|
31 |
|
32 |
+
def generate_audio(text, filename="detected_braille.mp3"):
|
33 |
+
"""Convert text to speech and save audio as file"""
|
34 |
tts = gTTS(text=text, lang='en')
|
35 |
+
tts.save(filename)
|
36 |
+
return filename
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# title
|
39 |
st.title("Braille Pattern Detection")
|
|
|
110 |
st.write(str_left_to_right)
|
111 |
|
112 |
# Convert detected Braille text to audio and play
|
113 |
+
if detected_text:
|
114 |
+
audio_file_path = generate_audio(detected_text)
|
115 |
|
116 |
except Exception as ex:
|
117 |
st.write("Please try again with images with types of JPG, JPEG, PNG ...")
|
118 |
|
119 |
+
with open(audio_file_path, "rb") as fl:
|
120 |
st.download_button(
|
121 |
+
"Download Braille Audio",
|
122 |
data=fl,
|
123 |
+
file_name="detected_braille.mp3",
|
124 |
+
mime="audio/mp3",
|
125 |
)
|