|
import streamlit as st |
|
import pyttsx3 |
|
import os |
|
|
|
|
|
engine = pyttsx3.init() |
|
|
|
|
|
st.title("Text-to-Speech Converter") |
|
st.write("Convert your text into speech quickly and easily.") |
|
|
|
|
|
user_input = st.text_area("Enter the text you want to convert to speech:", "") |
|
|
|
|
|
voice_option = st.selectbox("Select Voice:", ("Male", "Female")) |
|
rate = st.slider("Speech Rate:", min_value=100, max_value=200, value=150) |
|
|
|
|
|
voices = engine.getProperty("voices") |
|
engine.setProperty("voice", voices[0].id if voice_option == "Male" else voices[1].id) |
|
engine.setProperty("rate", rate) |
|
|
|
|
|
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() |
|
|
|
|
|
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") |
|
|
|
|
|
os.remove(audio_file) |
|
else: |
|
st.error("Please enter some text to convert.") |
|
|
|
|
|
st.markdown("Developed by [Your Name]. Deployed on Hugging Face Spaces.") |
|
|
|
|