import streamlit as st from gtts import gTTS import io # Function to generate audio from text def text_to_audio(text): tts = gTTS(text) audio = tts.save("output.mp3") return audio st.title("Voice Synthesis App") # Input form for the user to enter text user_input = st.text_area("Enter the text:") if st.button("Generate"): if user_input: audio = text_to_audio(user_input) # Display the audio st.audio("output.mp3", format="audio/mp3") # Create a download link for the audio file st.markdown("### Download the audio") with open("output.mp3", "rb") as audio_file: audio_bytes = audio_file.read() st.download_button( label="Click to download", data=audio_bytes, key="download_audio", file_name="output.mp3", mime="audio/mp3", ) st.write("Note: This app uses gTTS for text-to-speech conversion.")