import streamlit as st import pyttsx3 import os # Initialize the TTS engine engine = pyttsx3.init() # Configure Streamlit interface st.title("Text-to-Speech Converter") st.write("Convert your text into speech quickly and easily.") # User input for text user_input = st.text_area("Enter the text you want to convert to speech:", "") # Speed and voice options voice_option = st.selectbox("Select Voice:", ("Male", "Female")) rate = st.slider("Speech Rate:", min_value=100, max_value=200, value=150) # Apply user settings to the TTS engine voices = engine.getProperty("voices") engine.setProperty("voice", voices[0].id if voice_option == "Male" else voices[1].id) engine.setProperty("rate", rate) # Convert text to speech and save as audio file if st.button("Convert to Speech"): if user_input.strip(): audio_file = "output_audio.mp3" engine.save_to_file(user_input, audio_file) engine.runAndWait() # Display audio player and download link st.audio(audio_file, format="audio/mp3") with open(audio_file, "rb") as file: st.download_button("Download Audio", file, file_name="output_audio.mp3", mime="audio/mp3") # Clean up os.remove(audio_file) else: st.error("Please enter some text to convert.") # Footer st.markdown("Developed by [Your Name]. Deployed on Hugging Face Spaces.")