pm6six commited on
Commit
47a10c9
·
verified ·
1 Parent(s): 60ab783

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
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
- # Generate speech using gTTS
17
- tts = gTTS(text=text_input, lang="en")
18
- audio_file = "output.mp3"
19
- tts.save(audio_file)
 
20
 
21
- # Play the audio in the app
22
- st.audio(audio_file, format="audio/mp3")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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