Text2Speech / app.py
Engineer-Areeb's picture
Update app.py
cc14627 verified
import streamlit as st
import asyncio
import edge_tts
from io import BytesIO
st.set_page_config(page_title="Realistic Text-to-Speech", layout="centered")
st.title("πŸŽ™οΈ AI Voice Generator (Human-like)")
text = st.text_area("Enter text to convert into human-like speech:")
voice = st.selectbox("Choose a voice:", [
"en-US-AriaNeural", # Female (US)
"en-US-GuyNeural", # Male (US)
"en-GB-LibbyNeural", # Female (UK)
"en-IN-NeerjaNeural", # Female (India)
"en-IN-PrabhatNeural", # Male (India)
])
if st.button("Generate Audio"):
if not text.strip():
st.warning("Please enter some text.")
else:
async def generate_tts():
communicate = edge_tts.Communicate(text, voice)
audio_data = BytesIO()
async for chunk in communicate.stream():
if chunk["type"] == "audio":
audio_data.write(chunk["data"])
audio_data.seek(0)
return audio_data
audio_file = asyncio.run(generate_tts())
st.audio(audio_file, format="audio/mp3")
st.success("βœ… Done! Play the audio above.")