Spaces:
Sleeping
Sleeping
File size: 1,243 Bytes
c77c78f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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/).")
|