Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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", "
|
14 |
|
15 |
-
# Generate speech
|
16 |
if st.button("Generate Speech"):
|
17 |
if text_input:
|
18 |
-
#
|
19 |
-
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
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()
|