import streamlit as st import pyttsx3 # For text-to-speech import os # Initialize pyttsx3 TTS engine tts_engine = pyttsx3.init() # Configure TTS engine (optional) voices = tts_engine.getProperty("voices") tts_engine.setProperty("voice", voices[0].id) # Choose a voice tts_engine.setProperty("rate", 150) # Set speech rate # 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 audio_file = "output.mp3" tts_engine.save_to_file(text_input, audio_file) tts_engine.runAndWait() # Play the audio in the app st.audio(audio_file, format="audio/mp3") st.success("Audio generated successfully!")