File size: 944 Bytes
50afad7
 
 
 
 
 
8425469
 
50afad7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from gtts import gTTS

# 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 Selection
language = st.selectbox(
    "Select a Language:",
    options=["en", "fr", "es", "hi", "de"]
)

# Generate Speech
if st.button("Convert to Speech"):
    if text.strip():
        try:
            # Generate speech using gTTS
            tts = gTTS(text=text, lang=language)
            tts.save("output.mp3")
            st.audio("output.mp3", format="audio/mp3")
        except Exception as e:
            st.error(f"Error generating speech: {e}")
    else:
        st.warning("Please enter some text to convert to speech!")