import streamlit as st from gtts import gTTS import os import base64 # 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: try: # Generate speech using gTTS tts = gTTS(text=text_input, lang="en") audio_file = "output.wav" tts.save(audio_file) # Check if file exists if os.path.exists(audio_file): # Encode audio file to base64 with open(audio_file, "rb") as f: audio_data = f.read() audio_base64 = base64.b64encode(audio_data).decode() # Embed custom HTML audio player with speed adjustment audio_html = f"""