Spaces:
Sleeping
Sleeping
import streamlit as st | |
from gtts import gTTS | |
from io import BytesIO | |
# App title and description | |
st.title("π Text-to-Speech Converter") | |
st.write("Convert your text into speech using Google's gTTS library.") | |
# Text input | |
text_input = st.text_area("Enter your text:", placeholder="Type something here...", height=150) | |
# Language selection | |
language = st.selectbox("Select Language:", options=["en", "es", "fr", "de", "it", "hi"]) | |
# Generate speech button | |
if st.button("Convert to Speech"): | |
if text_input.strip(): | |
with st.spinner("Generating speech..."): | |
try: | |
# Convert text to speech | |
tts = gTTS(text_input, lang=language) | |
audio_bytes = BytesIO() | |
tts.write_to_fp(audio_bytes) | |
audio_bytes.seek(0) | |
# Display audio player | |
st.audio(audio_bytes, format="audio/mp3") | |
st.success("Speech generated successfully!") | |
except Exception as e: | |
st.error(f"An error occurred: {e}") | |
else: | |
st.warning("Please enter some text to convert.") | |
# Footer | |
st.write("---") | |
st.write("Built with [Streamlit](https://streamlit.io/) and [gTTS](https://pypi.org/project/gTTS/).") | |