| import streamlit as st | |
| from gtts import gTTS | |
| import os | |
| # Streamlit app UI | |
| st.title("Text-to-Audio App") | |
| st.text("This app converts your text input into audio using TTS.") | |
| # User input | |
| text_input = st.text_area("Enter some text:") | |
| if st.button("Generate Audio"): | |
| if not text_input.strip(): | |
| st.error("Please enter some text!") | |
| else: | |
| # Generate speech using gTTS | |
| tts = gTTS(text=text_input, lang="en") | |
| audio_file = "output.mp3" | |
| tts.save(audio_file) | |
| # Play the audio in the app | |
| st.audio(audio_file, format="audio/mp3") | |
| st.success("Audio generated successfully!") | |