Shahabmoin commited on
Commit
c77c78f
·
verified ·
1 Parent(s): d23c82a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py CHANGED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from gtts import gTTS
3
+ from io import BytesIO
4
+
5
+ # App title and description
6
+ st.title("🔊 Text-to-Speech Converter")
7
+ st.write("Convert your text into speech using Google's gTTS library.")
8
+
9
+ # Text input
10
+ text_input = st.text_area("Enter your text:", placeholder="Type something here...", height=150)
11
+
12
+ # Language selection
13
+ language = st.selectbox("Select Language:", options=["en", "es", "fr", "de", "it", "hi"])
14
+
15
+ # Generate speech button
16
+ if st.button("Convert to Speech"):
17
+ if text_input.strip():
18
+ with st.spinner("Generating speech..."):
19
+ try:
20
+ # Convert text to speech
21
+ tts = gTTS(text_input, lang=language)
22
+ audio_bytes = BytesIO()
23
+ tts.write_to_fp(audio_bytes)
24
+ audio_bytes.seek(0)
25
+
26
+ # Display audio player
27
+ st.audio(audio_bytes, format="audio/mp3")
28
+ st.success("Speech generated successfully!")
29
+ except Exception as e:
30
+ st.error(f"An error occurred: {e}")
31
+ else:
32
+ st.warning("Please enter some text to convert.")
33
+
34
+ # Footer
35
+ st.write("---")
36
+ st.write("Built with [Streamlit](https://streamlit.io/) and [gTTS](https://pypi.org/project/gTTS/).")