Nehal07 commited on
Commit
46d13a6
1 Parent(s): 4528e85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -61,11 +61,15 @@ if user_text:
61
  audio_file = "translated_audio.mp3"
62
  tts.save(audio_file)
63
 
64
- # Display the audio
65
- st.audio(audio_file, format="audio/mp3")
 
 
66
 
67
- # Remove the temporary audio file
68
- os.remove(audio_file)
 
 
69
 
70
  # CSS for the "Speak" button
71
  speak_button_css = """
@@ -81,4 +85,7 @@ speak_button_css = """
81
  # Speak button
82
  if st.button("Speak"):
83
  st.markdown(speak_button_css, unsafe_allow_html=True)
84
- st.audio(audio_file, format="audio/mp3")
 
 
 
 
61
  audio_file = "translated_audio.mp3"
62
  tts.save(audio_file)
63
 
64
+ # Check if the audio file exists
65
+ if os.path.exists(audio_file):
66
+ # Display the audio
67
+ st.audio(audio_file, format="audio/mp3")
68
 
69
+ # Remove the temporary audio file
70
+ os.remove(audio_file)
71
+ else:
72
+ st.warning("Audio file could not be generated.")
73
 
74
  # CSS for the "Speak" button
75
  speak_button_css = """
 
85
  # Speak button
86
  if st.button("Speak"):
87
  st.markdown(speak_button_css, unsafe_allow_html=True)
88
+ if os.path.exists(audio_file):
89
+ st.audio(audio_file, format="audio/mp3")
90
+ else:
91
+ st.warning("Audio file not found.")