EliSafina commited on
Commit
a11cb67
·
verified ·
1 Parent(s): 087cc4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from gtts import gTTS
3
  from io import BytesIO
 
4
 
5
  # Define the Streamlit app
6
  def main():
@@ -10,21 +11,27 @@ def main():
10
  text_input = st.text_area("Enter text to convert to speech", height=150)
11
 
12
  # Language selection
13
- language = st.selectbox("Select language", ["en", "fr", "es", "ru", "hi"])
14
 
15
- # Generate speech
16
  if st.button("Generate Speech"):
17
  if text_input:
18
- # Create a gTTS object
19
- tts = gTTS(text_input, lang=language)
 
 
20
 
21
- # Create a BytesIO object to store the audio data
22
- audio_stream = BytesIO()
23
 
24
- # Save speech to the BytesIO object
25
- tts.write_to_fp(audio_stream)
26
 
27
- # Display audio player
 
 
 
 
28
  st.audio(audio_stream)
29
 
30
- main()
 
1
  import streamlit as st
2
  from gtts import gTTS
3
  from io import BytesIO
4
+ import time
5
 
6
  # Define the Streamlit app
7
  def main():
 
11
  text_input = st.text_area("Enter text to convert to speech", height=150)
12
 
13
  # Language selection
14
+ language = st.selectbox("Select language", ["en", "fr", "es", "de"])
15
 
16
+ # Generate speech button
17
  if st.button("Generate Speech"):
18
  if text_input:
19
+ # Display spinner while generating speech
20
+ with st.spinner("Generating speech..."):
21
+ # Create a gTTS object
22
+ tts = gTTS(text_input, lang=language)
23
 
24
+ # Create a BytesIO object to store the audio data
25
+ audio_stream = BytesIO()
26
 
27
+ # Save speech to the BytesIO object
28
+ tts.write_to_fp(audio_stream)
29
 
30
+ # Simulate delay to mimic speech generation time
31
+ time.sleep(2)
32
+
33
+ # Display success message and audio player
34
+ st.success("Speech generated successfully!")
35
  st.audio(audio_stream)
36
 
37
+ main()