Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,31 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
import os
|
4 |
|
5 |
-
#
|
6 |
-
engine = pyttsx3.init()
|
7 |
-
|
8 |
-
# Configure Streamlit interface
|
9 |
st.title("Text-to-Speech Converter")
|
10 |
-
st.write("
|
11 |
-
|
12 |
-
# User input for text
|
13 |
-
user_input = st.text_area("Enter the text you want to convert to speech:", "")
|
14 |
-
|
15 |
-
# Speed and voice options
|
16 |
-
voice_option = st.selectbox("Select Voice:", ("Male", "Female"))
|
17 |
-
rate = st.slider("Speech Rate:", min_value=100, max_value=200, value=150)
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
engine.setProperty("voice", voices[0].id if voice_option == "Male" else voices[1].id)
|
22 |
-
engine.setProperty("rate", rate)
|
23 |
|
24 |
-
# Convert text to speech and save as audio file
|
25 |
if st.button("Convert to Speech"):
|
26 |
if user_input.strip():
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
# Display audio player
|
32 |
-
st.audio(
|
33 |
-
|
34 |
-
|
|
|
|
|
35 |
|
36 |
# Clean up
|
37 |
-
os.remove(
|
38 |
else:
|
39 |
-
st.error("Please enter some text
|
40 |
|
41 |
# Footer
|
42 |
st.markdown("Developed by [Your Name]. Deployed on Hugging Face Spaces.")
|
43 |
-
|
|
|
1 |
import streamlit as st
|
2 |
+
from gtts import gTTS
|
3 |
import os
|
4 |
|
5 |
+
# Streamlit app setup
|
|
|
|
|
|
|
6 |
st.title("Text-to-Speech Converter")
|
7 |
+
st.write("Enter your text below to convert it into speech.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
# Text input
|
10 |
+
user_input = st.text_area("Enter text here:", "")
|
|
|
|
|
11 |
|
|
|
12 |
if st.button("Convert to Speech"):
|
13 |
if user_input.strip():
|
14 |
+
# Generate speech
|
15 |
+
tts = gTTS(user_input, lang="en")
|
16 |
+
tts.save("output.mp3")
|
17 |
|
18 |
+
# Display audio player
|
19 |
+
st.audio("output.mp3", format="audio/mp3")
|
20 |
+
|
21 |
+
# Provide download link
|
22 |
+
with open("output.mp3", "rb") as audio_file:
|
23 |
+
st.download_button("Download Audio", audio_file, file_name="output.mp3", mime="audio/mp3")
|
24 |
|
25 |
# Clean up
|
26 |
+
os.remove("output.mp3")
|
27 |
else:
|
28 |
+
st.error("Please enter some text.")
|
29 |
|
30 |
# Footer
|
31 |
st.markdown("Developed by [Your Name]. Deployed on Hugging Face Spaces.")
|
|