Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import edge_tts
|
3 |
+
import asyncio
|
4 |
+
|
5 |
+
async def tts(text, language):
|
6 |
+
tts = edge_tts.Communicate(text, voice=language)
|
7 |
+
await tts.save("output.mp3")
|
8 |
+
return "output.mp3"
|
9 |
+
|
10 |
+
def generate_tts(text, language):
|
11 |
+
return asyncio.run(tts(text, language))
|
12 |
+
|
13 |
+
languages = {
|
14 |
+
"English": "en-US-JennyNeural",
|
15 |
+
"Indonesian": "id-ID-GadisNeural",
|
16 |
+
"Korean": "ko-KR-SunHiNeural",
|
17 |
+
"Japanese": "ja-JP-NanamiNeural",
|
18 |
+
"Malaysian": "ms-MY-OsmanNeural"
|
19 |
+
}
|
20 |
+
|
21 |
+
def get_audio_file(text, lang_key):
|
22 |
+
language = languages[lang_key]
|
23 |
+
return generate_tts(text, language)
|
24 |
+
|
25 |
+
st.title("Blane TTS")
|
26 |
+
|
27 |
+
text_input = st.text_area("Input Text")
|
28 |
+
language_input = st.selectbox("Select Language", list(languages.keys()))
|
29 |
+
tts_button = st.button("Generate TTS")
|
30 |
+
|
31 |
+
if tts_button:
|
32 |
+
audio_file = get_audio_file(text_input, language_input)
|
33 |
+
audio_bytes = open(audio_file, "rb").read()
|
34 |
+
st.audio(audio_bytes, format="audio/mp3")
|