import streamlit as st # from gtts import gTTS import io import torch from TTS.api import TTS # 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") # Get device device = "cuda" if torch.cuda.is_available() else "cpu" # List available 🐸TTS models print(TTS().list_models()) # Init TTS tts = TTS("tts_models/en/ljspeech/overflow").to(device) # 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) # Text to speech to a file tts.tts_to_file(text="Hello world!", file_path="output.wav") # Display the audio st.audio("output.wav", format="audio/wav") # Create a download link for the audio file st.markdown("### Download the audio") with open("output.wav", "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.wav", mime="audio/wav", ) st.write("Note: This app uses gTTS for text-to-speech conversion.")