Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
โข
60d5502
1
Parent(s):
c4ad0e3
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
import requests
|
3 |
import streamlit.components.v1 as components
|
4 |
from gtts import gTTS
|
|
|
5 |
from io import BytesIO
|
6 |
|
7 |
# ํ์ด์ง ์ค์
|
@@ -37,65 +38,37 @@ if selected_menu in menus:
|
|
37 |
else:
|
38 |
st.session_state['current_sub_menu'] = ''
|
39 |
|
|
|
40 |
# 'Sound' ๋ฉ๋ด์ 'TTS(Voice)' ์ ํ ์
|
41 |
if selected_menu == "Sound" and selected_sub_menu == "TTS(Voice)":
|
42 |
st.header("Text-to-Speech")
|
43 |
# ํ
์คํธ ์
๋ ฅ
|
44 |
text = st.text_area("Enter text to synthesize", "Hello, welcome to ViDraft TTS service.")
|
45 |
|
46 |
-
# ์ธ์ด
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
(
|
55 |
-
|
56 |
-
(
|
57 |
-
|
58 |
-
("French", "fr-FR"),
|
59 |
-
("French, Canada", "fr-CA"),
|
60 |
-
("German", "de-DE"),
|
61 |
-
("Gujarati", "gu-IN"),
|
62 |
-
("Hindi", "hi-IN"),
|
63 |
-
("Indonesian", "id-ID"),
|
64 |
-
("Italian", "it-IT"),
|
65 |
-
("Japanese", "ja-JP"),
|
66 |
-
("Kannada", "kn-IN"),
|
67 |
-
("Korean", "ko-KR"),
|
68 |
-
("Malayalam", "ml-IN"),
|
69 |
-
("Marathi", "mr-IN"),
|
70 |
-
("Norwegian", "nb-NO"),
|
71 |
-
("Polish", "pl-PL"),
|
72 |
-
("Portuguese, Brazil", "pt-BR"),
|
73 |
-
("Portuguese, Portugal", "pt-PT"),
|
74 |
-
("Russian", "ru-RU"),
|
75 |
-
("Spanish, Spain", "es-ES"),
|
76 |
-
("Spanish, Mexico", "es-MX"),
|
77 |
-
("Swedish", "sv-SE"),
|
78 |
-
("Tamil", "ta-IN"),
|
79 |
-
("Telugu", "te-IN"),
|
80 |
-
("Thai", "th-TH"),
|
81 |
-
("Turkish", "tr-TR"),
|
82 |
-
("Ukrainian", "uk-UA"),
|
83 |
-
("Vietnamese", "vi-VN"),
|
84 |
-
]
|
85 |
-
# 'English, US'๋ฅผ ๊ธฐ๋ณธ ์ธ์ด๋ก ์ค์
|
86 |
-
default_lang_index = languages.index(("English, US", "en-US"))
|
87 |
-
language = st.selectbox("Choose Language", languages, format_func=lambda x: x[0], index=default_lang_index, key='language_select')
|
88 |
|
89 |
# 'Synthesize' ๋ฒํผ
|
90 |
if st.button("Synthesize"):
|
91 |
if text:
|
92 |
try:
|
93 |
-
|
94 |
-
tts = gTTS(text=text, lang=
|
95 |
audio_file = BytesIO()
|
96 |
tts.write_to_fp(audio_file)
|
97 |
audio_file.seek(0)
|
98 |
-
|
|
|
99 |
except Exception as e:
|
100 |
st.error(f"Error: {e}")
|
101 |
else:
|
|
|
2 |
import requests
|
3 |
import streamlit.components.v1 as components
|
4 |
from gtts import gTTS
|
5 |
+
from gtts.lang import tts_langs
|
6 |
from io import BytesIO
|
7 |
|
8 |
# ํ์ด์ง ์ค์
|
|
|
38 |
else:
|
39 |
st.session_state['current_sub_menu'] = ''
|
40 |
|
41 |
+
|
42 |
# 'Sound' ๋ฉ๋ด์ 'TTS(Voice)' ์ ํ ์
|
43 |
if selected_menu == "Sound" and selected_sub_menu == "TTS(Voice)":
|
44 |
st.header("Text-to-Speech")
|
45 |
# ํ
์คํธ ์
๋ ฅ
|
46 |
text = st.text_area("Enter text to synthesize", "Hello, welcome to ViDraft TTS service.")
|
47 |
|
48 |
+
# ์ง์๋๋ ์ธ์ด ๋ชฉ๋ก์ ๋ถ๋ฌ์ต๋๋ค.
|
49 |
+
languages_dict = tts_langs()
|
50 |
+
# ISO 639-1 ํ์ค์ ๋ฐ๋ผ ๋ ๊ธ์ ์ฝ๋๋ฅผ ๊ฐ์ง ์ธ์ด๋ง ํํฐ๋ง
|
51 |
+
two_letter_languages = {code: lang for code, lang in languages_dict.items() if len(code) == 2}
|
52 |
+
|
53 |
+
# ์ธ์ด ์ ํ์ ์ํ selectbox๋ฅผ ์์ฑํฉ๋๋ค.
|
54 |
+
selected_language_code = st.selectbox(
|
55 |
+
"Choose Language",
|
56 |
+
options=list(two_letter_languages.keys()),
|
57 |
+
format_func=lambda x: f"{two_letter_languages[x]} ({x})",
|
58 |
+
index=list(two_letter_languages.keys()).index('en') # 'en'์ ๊ธฐ๋ณธ ์ธ์ด๋ก ์ค์
|
59 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
# 'Synthesize' ๋ฒํผ
|
62 |
if st.button("Synthesize"):
|
63 |
if text:
|
64 |
try:
|
65 |
+
# ์ ํ๋ ์ธ์ด๋ก gTTS ๊ฐ์ฒด ์์ฑ
|
66 |
+
tts = gTTS(text=text, lang=selected_language_code, slow=False)
|
67 |
audio_file = BytesIO()
|
68 |
tts.write_to_fp(audio_file)
|
69 |
audio_file.seek(0)
|
70 |
+
# ์์ฑ๋ ์ค๋์ค ํ์ผ์ ์ฌ์
|
71 |
+
st.audio(audio_file, format="audio/mp3")
|
72 |
except Exception as e:
|
73 |
st.error(f"Error: {e}")
|
74 |
else:
|