Engineer-Areeb commited on
Commit
98c10c3
·
verified ·
1 Parent(s): 238a6bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -16
app.py CHANGED
@@ -1,22 +1,32 @@
1
  import streamlit as st
2
- from gtts import gTTS
3
- import os
4
  from io import BytesIO
5
 
6
- st.set_page_config(page_title="Text to Speech App", layout="centered")
7
- st.title("🗣️ Text to Speech Converter")
8
 
9
- text = st.text_area("Enter the text you want to convert to speech:")
10
 
11
- if st.button("Convert to Audio"):
12
- if text.strip() == "":
13
- st.warning("Please enter some text first.")
 
 
 
 
 
 
 
 
14
  else:
15
- tts = gTTS(text)
16
- audio_bytes = BytesIO()
17
- tts.write_to_fp(audio_bytes)
18
- audio_bytes.seek(0)
19
-
20
- st.success("✅ Conversion successful!")
21
- st.audio(audio_bytes, format="audio/mp3")
22
-
 
 
 
1
  import streamlit as st
2
+ import asyncio
3
+ import edge_tts
4
  from io import BytesIO
5
 
6
+ st.set_page_config(page_title="Realistic Text-to-Speech", layout="centered")
7
+ st.title("🎙️ AI Voice Generator (Realistic)")
8
 
9
+ text = st.text_area("Enter text to convert into human-like speech:")
10
 
11
+ voice = st.selectbox("Choose a voice:", [
12
+ "en-US-AriaNeural", # Female
13
+ "en-US-GuyNeural", # Male
14
+ "en-GB-LibbyNeural", # British Female
15
+ "en-IN-NeerjaNeural", # Indian Female
16
+ "en-IN-PrabhatNeural", # Indian Male
17
+ ])
18
+
19
+ if st.button("Generate Audio"):
20
+ if not text.strip():
21
+ st.warning("Please enter some text.")
22
  else:
23
+ async def generate_tts():
24
+ communicate = edge_tts.Communicate(text, voice)
25
+ audio_stream = BytesIO()
26
+ await communicate.save_to_stream(audio_stream)
27
+ audio_stream.seek(0)
28
+ return audio_stream
29
+
30
+ audio_file = asyncio.run(generate_tts())
31
+ st.audio(audio_file, format="audio/mp3")
32
+ st.success("✅ Done! Play the audio above.")