Engineer-Areeb commited on
Commit
cc14627
·
verified ·
1 Parent(s): 9616d65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -4,16 +4,16 @@ 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"):
@@ -22,10 +22,12 @@ if st.button("Generate Audio"):
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")
 
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 (Human-like)")
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 (US)
13
+ "en-US-GuyNeural", # Male (US)
14
+ "en-GB-LibbyNeural", # Female (UK)
15
+ "en-IN-NeerjaNeural", # Female (India)
16
+ "en-IN-PrabhatNeural", # Male (India)
17
  ])
18
 
19
  if st.button("Generate Audio"):
 
22
  else:
23
  async def generate_tts():
24
  communicate = edge_tts.Communicate(text, voice)
25
+ audio_data = BytesIO()
26
+ async for chunk in communicate.stream():
27
+ if chunk["type"] == "audio":
28
+ audio_data.write(chunk["data"])
29
+ audio_data.seek(0)
30
+ return audio_data
31
 
32
  audio_file = asyncio.run(generate_tts())
33
  st.audio(audio_file, format="audio/mp3")