Update app.py
Browse files
app.py
CHANGED
|
@@ -13,13 +13,29 @@ if st.button("Generate Audio"):
|
|
| 13 |
if not text_input.strip():
|
| 14 |
st.error("Please enter some text!")
|
| 15 |
else:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
st.success("Audio generated successfully!")
|
| 25 |
|
|
|
|
| 13 |
if not text_input.strip():
|
| 14 |
st.error("Please enter some text!")
|
| 15 |
else:
|
| 16 |
+
try:
|
| 17 |
+
# Generate speech using gTTS
|
| 18 |
+
tts = gTTS(text=text_input, lang="en")
|
| 19 |
+
audio_file = "output.wav"
|
| 20 |
+
tts.save(audio_file)
|
| 21 |
|
| 22 |
+
# Check if file exists
|
| 23 |
+
if os.path.exists(audio_file):
|
| 24 |
+
# Play audio in app
|
| 25 |
+
st.audio(audio_file, format="audio/wav")
|
| 26 |
+
st.success("Audio generated successfully!")
|
| 27 |
+
|
| 28 |
+
# Provide download option
|
| 29 |
+
with open(audio_file, "rb") as f:
|
| 30 |
+
st.download_button(
|
| 31 |
+
label="Download Audio",
|
| 32 |
+
data=f.read(),
|
| 33 |
+
file_name="output.wav",
|
| 34 |
+
mime="audio/wav",
|
| 35 |
+
)
|
| 36 |
+
else:
|
| 37 |
+
st.error("Audio file could not be generated.")
|
| 38 |
+
except Exception as e:
|
| 39 |
+
st.error(f"An error occurred: {e}")
|
| 40 |
|
|
|
|
| 41 |
|