Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import asyncio
|
|
4 |
import tempfile
|
5 |
import os
|
6 |
from typing import Dict
|
|
|
7 |
|
8 |
async def text_to_speech(text: str, voice: str) -> str:
|
9 |
output_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
|
@@ -15,18 +16,34 @@ async def list_voices() -> Dict[str, Dict]:
|
|
15 |
voices = await edge_tts.list_voices()
|
16 |
return {v['ShortName']: {'name': v['ShortName'], 'language': v['Locale']} for v in voices}
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
async def main():
|
19 |
st.title("OpenSpeech-TTS")
|
20 |
st.write("An API to generate high quality speech with minimal hardware fast and efficiently.")
|
21 |
st.write("https://github.com/PantelisDeveloping/openspeech-tts/")
|
22 |
|
23 |
-
# Get voices
|
24 |
voices = await list_voices()
|
|
|
25 |
|
26 |
# Text-to-Speech
|
27 |
st.header("Text-to-Speech")
|
28 |
text_input = st.text_area("Enter text to convert to speech:")
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
if st.button("Generate Speech"):
|
32 |
if not text_input:
|
@@ -39,7 +56,9 @@ async def main():
|
|
39 |
|
40 |
# List Available Voices
|
41 |
st.header("Available Voices")
|
42 |
-
|
|
|
|
|
43 |
|
44 |
if __name__ == '__main__':
|
45 |
asyncio.run(main())
|
|
|
4 |
import tempfile
|
5 |
import os
|
6 |
from typing import Dict
|
7 |
+
from collections import defaultdict
|
8 |
|
9 |
async def text_to_speech(text: str, voice: str) -> str:
|
10 |
output_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
|
|
|
16 |
voices = await edge_tts.list_voices()
|
17 |
return {v['ShortName']: {'name': v['ShortName'], 'language': v['Locale']} for v in voices}
|
18 |
|
19 |
+
def process_voices(voices: Dict[str, Dict]) -> Dict[str, Dict[str, str]]:
|
20 |
+
processed_voices = defaultdict(dict)
|
21 |
+
for full_name, details in voices.items():
|
22 |
+
lang, speaker_name = full_name.split('-')[:2]
|
23 |
+
processed_voices[lang][speaker_name] = full_name
|
24 |
+
return dict(processed_voices)
|
25 |
+
|
26 |
async def main():
|
27 |
st.title("OpenSpeech-TTS")
|
28 |
st.write("An API to generate high quality speech with minimal hardware fast and efficiently.")
|
29 |
st.write("https://github.com/PantelisDeveloping/openspeech-tts/")
|
30 |
|
31 |
+
# Get voices and process them
|
32 |
voices = await list_voices()
|
33 |
+
processed_voices = process_voices(voices)
|
34 |
|
35 |
# Text-to-Speech
|
36 |
st.header("Text-to-Speech")
|
37 |
text_input = st.text_area("Enter text to convert to speech:")
|
38 |
+
|
39 |
+
# Two-step voice selection
|
40 |
+
col1, col2 = st.columns(2)
|
41 |
+
with col1:
|
42 |
+
selected_language = st.selectbox("Select language:", list(processed_voices.keys()))
|
43 |
+
with col2:
|
44 |
+
selected_speaker = st.selectbox("Select speaker:", list(processed_voices[selected_language].keys()))
|
45 |
+
|
46 |
+
selected_voice = processed_voices[selected_language][selected_speaker]
|
47 |
|
48 |
if st.button("Generate Speech"):
|
49 |
if not text_input:
|
|
|
56 |
|
57 |
# List Available Voices
|
58 |
st.header("Available Voices")
|
59 |
+
for language, speakers in processed_voices.items():
|
60 |
+
st.subheader(language)
|
61 |
+
st.write(", ".join(speakers.keys()))
|
62 |
|
63 |
if __name__ == '__main__':
|
64 |
asyncio.run(main())
|