Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,9 @@ import streamlit as st
|
|
12 |
import torch
|
13 |
from ultralyticsplus import YOLO, render_result
|
14 |
|
|
|
|
|
|
|
15 |
from convert import convert_to_braille_unicode, parse_xywh_and_class
|
16 |
|
17 |
|
@@ -26,6 +29,15 @@ def load_image(image_path):
|
|
26 |
image = PIL.Image.open(image_path)
|
27 |
return image
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
# title
|
31 |
st.title("Braille Pattern Detection")
|
@@ -101,6 +113,7 @@ try:
|
|
101 |
)
|
102 |
st.write(str_left_to_right)
|
103 |
|
|
|
104 |
if detected_text:
|
105 |
play_audio(detected_text)
|
106 |
|
|
|
12 |
import torch
|
13 |
from ultralyticsplus import YOLO, render_result
|
14 |
|
15 |
+
from gtts import gTTS
|
16 |
+
import os
|
17 |
+
|
18 |
from convert import convert_to_braille_unicode, parse_xywh_and_class
|
19 |
|
20 |
|
|
|
29 |
image = PIL.Image.open(image_path)
|
30 |
return image
|
31 |
|
32 |
+
def play_audio(text):
|
33 |
+
"""Convert text to speech and play audio in Streamlit"""
|
34 |
+
tts = gTTS(text=text, lang='en')
|
35 |
+
tts.save("detected_braille.mp3")
|
36 |
+
audio_file = open("detected_braille.mp3", "rb")
|
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")
|
|
|
113 |
)
|
114 |
st.write(str_left_to_right)
|
115 |
|
116 |
+
# Convert detected Braille text to audio and play
|
117 |
if detected_text:
|
118 |
play_audio(detected_text)
|
119 |
|