|
import streamlit as st |
|
from gtts import gTTS |
|
import os |
|
|
|
|
|
st.title("Text-to-Audio App") |
|
st.text("This app converts your text input into audio using TTS.") |
|
|
|
|
|
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: |
|
try: |
|
|
|
tts = gTTS(text=text_input, lang="en") |
|
audio_file = "output.wav" |
|
tts.save(audio_file) |
|
|
|
|
|
if os.path.exists(audio_file): |
|
|
|
st.audio(audio_file, format="audio/wav") |
|
st.success("Audio generated successfully!") |
|
|
|
|
|
with open(audio_file, "rb") as f: |
|
st.download_button( |
|
label="Download Audio", |
|
data=f.read(), |
|
file_name="output.wav", |
|
mime="audio/wav", |
|
) |
|
else: |
|
st.error("Audio file could not be generated.") |
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
|
|
|
|
|