Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from gtts import gTTS
|
3 |
+
import os
|
4 |
+
from playsound import playsound
|
5 |
+
|
6 |
+
# App Title
|
7 |
+
st.title("Text-to-Speech Streamlit App")
|
8 |
+
|
9 |
+
# User Input for Text
|
10 |
+
text_input = st.text_area("Enter Text Here:", "Hello, how can I assist you today?")
|
11 |
+
|
12 |
+
# Language selection
|
13 |
+
language = st.selectbox("Select Language", ["en", "es", "fr", "de", "it"])
|
14 |
+
|
15 |
+
# Generate Speech button
|
16 |
+
if st.button("Generate Speech"):
|
17 |
+
if text_input:
|
18 |
+
# Convert text to speech
|
19 |
+
tts = gTTS(text=text_input, lang=language, slow=False)
|
20 |
+
|
21 |
+
# Save the generated speech to a file
|
22 |
+
tts.save("output.mp3")
|
23 |
+
|
24 |
+
# Play the speech
|
25 |
+
playsound("output.mp3")
|
26 |
+
|
27 |
+
# Display success message
|
28 |
+
st.success("Speech has been generated and played successfully.")
|
29 |
+
else:
|
30 |
+
st.warning("Please enter some text.")
|