|
import streamlit as st |
|
from gtts import gTTS |
|
from io import BytesIO |
|
|
|
|
|
st.title("π Text-to-Speech Converter") |
|
st.write("Convert your text into speech using Google's gTTS library.") |
|
|
|
|
|
text_input = st.text_area("Enter your text:", placeholder="Type something here...", height=150) |
|
|
|
|
|
language = st.selectbox("Select Language:", options=["en", "es", "fr", "de", "it", "hi"]) |
|
|
|
|
|
if st.button("Convert to Speech"): |
|
if text_input.strip(): |
|
with st.spinner("Generating speech..."): |
|
try: |
|
|
|
tts = gTTS(text_input, lang=language) |
|
audio_bytes = BytesIO() |
|
tts.write_to_fp(audio_bytes) |
|
audio_bytes.seek(0) |
|
|
|
|
|
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.") |
|
|
|
|
|
st.write("---") |
|
st.write("Built with [Streamlit](https://streamlit.io/) and [gTTS](https://pypi.org/project/gTTS/).") |
|
|