Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -103,39 +103,34 @@ try:
|
|
103 |
result += str_left_to_right + "\n"
|
104 |
st.write(str_left_to_right)
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
tts = gTTS(text=text, lang=lang)
|
109 |
-
# 保存音频文件
|
110 |
-
tts.save("./output_audio/output.mp3")
|
111 |
-
|
112 |
-
audio_file_path = "./output_audio/output.mp3"
|
113 |
-
|
114 |
-
text_to_speech_gtts(result)
|
115 |
|
116 |
-
def
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
pygame.mixer.music.play()
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
continue
|
127 |
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
-
|
132 |
except Exception as ex:
|
133 |
-
st.write("
|
134 |
-
|
135 |
-
with open(audio_file_path, "rb") as fl:
|
136 |
-
st.download_button(
|
137 |
-
"Download Braille Audio",
|
138 |
-
data=fl,
|
139 |
-
file_name="detected_braille.mp3",
|
140 |
-
mime="audio/mp3",
|
141 |
-
)
|
|
|
103 |
result += str_left_to_right + "\n"
|
104 |
st.write(str_left_to_right)
|
105 |
|
106 |
+
AUDIO_OUTPUT_FOLDER = "./output_audio"
|
107 |
+
os.makedirs(AUDIO_OUTPUT_FOLDER, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
+
def text_to_speech_gtts(text, lang='en', filename="output.mp3"):
|
110 |
+
"""将文本转换为语音并保存音频文件"""
|
111 |
+
tts = gTTS(text=text, lang=lang)
|
112 |
+
audio_path = os.path.join(AUDIO_OUTPUT_FOLDER, filename)
|
113 |
+
tts.save(audio_path)
|
114 |
+
return audio_path
|
|
|
115 |
|
116 |
+
# 示例检测结果文本
|
117 |
+
detected_text = "This is a sample Braille detection result."
|
|
|
118 |
|
119 |
+
try:
|
120 |
+
# 生成语音文件
|
121 |
+
audio_file_path = text_to_speech_gtts(detected_text)
|
122 |
+
|
123 |
+
# 在 Streamlit 中播放音频
|
124 |
+
st.audio(audio_file_path, format="audio/mp3")
|
125 |
+
|
126 |
+
# 提供下载按钮
|
127 |
+
with open(audio_file_path, "rb") as audio_file:
|
128 |
+
st.download_button(
|
129 |
+
label="Download Braille Audio",
|
130 |
+
data=audio_file,
|
131 |
+
file_name="detected_braille.mp3",
|
132 |
+
mime="audio/mp3",
|
133 |
+
)
|
134 |
|
|
|
135 |
except Exception as ex:
|
136 |
+
st.write("An error occurred while processing the audio.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|