File size: 935 Bytes
30ae21b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
import streamlit as st
import edge_tts
import asyncio

async def tts(text, language):
    tts = edge_tts.Communicate(text, voice=language)
    await tts.save("output.mp3")
    return "output.mp3"

def generate_tts(text, language):
    return asyncio.run(tts(text, language))

languages = {
    "English": "en-US-JennyNeural",
    "Indonesian": "id-ID-GadisNeural",
    "Korean": "ko-KR-SunHiNeural",
    "Japanese": "ja-JP-NanamiNeural",
    "Malaysian": "ms-MY-OsmanNeural"
}

def get_audio_file(text, lang_key):
    language = languages[lang_key]
    return generate_tts(text, language)

st.title("Blane TTS")

text_input = st.text_area("Input Text")
language_input = st.selectbox("Select Language", list(languages.keys()))
tts_button = st.button("Generate TTS")

if tts_button:
    audio_file = get_audio_file(text_input, language_input)
    audio_bytes = open(audio_file, "rb").read()
    st.audio(audio_bytes, format="audio/mp3")