import streamlit as st import pyttsx3 # Initialize TTS engine engine = pyttsx3.init() # Configure available voices voices = engine.getProperty('voices') # Streamlit App Title st.title("Text-to-Speech Application") st.markdown(""" A text-to-speech application supporting multiple languages and voices. Customize the speech synthesis settings as per your preferences! """) # User Input for Text text = st.text_area("Enter the text you want to convert to speech:", placeholder="Type something here...") # Language and Voice Selection language = st.selectbox( "Select a Language:", options=["English (US)", "English (UK)", "Hindi", "French", "Spanish"] ) voice_gender = st.radio( "Select Voice Gender:", options=["Male", "Female"] ) # Customize Voice Rate and Volume rate = st.slider("Adjust Speech Rate:", min_value=100, max_value=300, value=200, step=10) volume = st.slider("Adjust Volume:", min_value=0.0, max_value=1.0, value=1.0, step=0.1) # Generate Speech if st.button("Convert to Speech"): if text.strip(): # Set language and voice properties if language == "English (US)": selected_voice = voices[0] # Adjust based on your system's available voices elif language == "English (UK)": selected_voice = voices[1] elif language == "Hindi": selected_voice = voices[2] # Requires Hindi TTS setup in OS elif language == "French": selected_voice = voices[3] elif language == "Spanish": selected_voice = voices[4] else: selected_voice = voices[0] # Set voice engine.setProperty('voice', selected_voice.id) # Set gender if voice_gender == "Female": for v in voices: if "female" in v.name.lower(): engine.setProperty('voice', v.id) break # Set rate and volume engine.setProperty('rate', rate) engine.setProperty('volume', volume) # Convert to speech engine.save_to_file(text, 'output.mp3') engine.runAndWait() st.audio('output.mp3', format="audio/mp3", start_time=0) else: st.warning("Please enter some text to convert to speech!")