muqeet1234's picture
Update app.py
5c147df verified
raw
history blame contribute delete
880 Bytes
import streamlit as st
from gtts import gTTS
import os
# Streamlit app setup
st.title("Text-to-Speech Converter")
st.write("Enter your text below to convert it into speech.")
# Text input
user_input = st.text_area("Enter text here:", "")
if st.button("Convert to Speech"):
if user_input.strip():
# Generate speech
tts = gTTS(user_input, lang="en")
tts.save("output.mp3")
# Display audio player
st.audio("output.mp3", format="audio/mp3")
# Provide download link
with open("output.mp3", "rb") as audio_file:
st.download_button("Download Audio", audio_file, file_name="output.mp3", mime="audio/mp3")
# Clean up
os.remove("output.mp3")
else:
st.error("Please enter some text.")
# Footer
st.markdown("Developed by [Your Name]. Deployed on Hugging Face Spaces.")