seawolf2357 commited on
Commit
60d5502
โ€ข
1 Parent(s): c4ad0e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -45
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
- languages = [
48
- ("Arabic", "ar-XA"),
49
- ("Bengali", "bn-IN"),
50
- ("Chinese, Mandarin (Simplified)", "cmn-CN"),
51
- ("Chinese, Mandarin (Traditional)", "cmn-TW"),
52
- ("Danish", "da-DK"),
53
- ("Dutch", "nl-NL"),
54
- ("English, Australia", "en-AU"),
55
- ("English, India", "en-IN"),
56
- ("English, UK", "en-GB"),
57
- ("English, US", "en-US"), # ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์„ค์ •๋  ์–ธ์–ด
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
- tts_language = dict(languages)[language]
94
- tts = gTTS(text=text, lang=tts_language, slow=False)
95
  audio_file = BytesIO()
96
  tts.write_to_fp(audio_file)
97
  audio_file.seek(0)
98
- st.audio(audio_file, format='audio/mp3')
 
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: