File size: 1,393 Bytes
8cd0ff6
2ecc02f
d7aaead
8cd0ff6
2ecc02f
 
8cd0ff6
2ecc02f
8cd0ff6
2ecc02f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7aaead
2ecc02f
 
 
 
 
 
 
 
 
d7aaead
2ecc02f
 
8cd0ff6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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.")