shukdevdatta123 commited on
Commit
6ad599b
·
verified ·
1 Parent(s): 1778b0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -33
app.py CHANGED
@@ -3,7 +3,6 @@ from kokoro import KPipeline
3
  import soundfile as sf
4
  import io
5
  import os
6
- from langdetect import detect # Language detection library
7
 
8
  # Install espeak-ng if not installed
9
  if not os.system("which espeak-ng"):
@@ -14,7 +13,6 @@ else:
14
 
15
  # Streamlit App UI Setup
16
  st.title("Text-to-Speech with Kokoro")
17
-
18
  # Expander section to display information in multiple languages
19
  with st.expander("Sample Prompt!"):
20
  st.markdown("""
@@ -27,7 +25,6 @@ with st.expander("Sample Prompt!"):
27
  - 我叫苏赫德夫。(In Chinese)
28
  - 私の名前はスクデフです。(In Japanese)
29
  """)
30
-
31
  st.sidebar.header("Configuration & Instructions")
32
 
33
  # Sidebar Instructions
@@ -64,35 +61,9 @@ st.sidebar.markdown("""
64
  ### Courtesy: [Kokoro](https://huggingface.co/hexgrad/Kokoro-82M?fbclid=IwY2xjawIKqzxleHRuA2FlbQIxMAABHaf9GldgYOzXktNuoRtNKqd-aL7r-S7zPGyC8ttYOiG2zYfQqLyV4Qm75A_aem_0wKLC2C87ZZ2F04WjPJbtA)
65
  """)
66
 
67
- # Language Detection Function
68
- def detect_language(text):
69
- try:
70
- lang = detect(text)
71
- return lang
72
- except Exception as e:
73
- st.error("Error detecting language: " + str(e))
74
- return None
75
-
76
  # User input for text, language, and voice settings
77
  input_text = st.text_area("Enter your text here", placeholder="The sky above the port was the color of television...")
78
- auto_detect_lang = detect_language(input_text)
79
-
80
- # Set detected language to the selectbox (if detected)
81
- if auto_detect_lang:
82
- lang_map = {
83
- 'en': 'a', # American English
84
- 'es': 'e', # Spanish
85
- 'fr': 'f', # French
86
- 'hi': 'h', # Hindi
87
- 'it': 'i', # Italian
88
- 'pt': 'p', # Portuguese
89
- 'zh': 'z', # Chinese
90
- 'ja': 'j' # Japanese
91
- }
92
- lang_code = lang_map.get(auto_detect_lang, 'a') # Default to English if not in map
93
- else:
94
- lang_code = st.selectbox("Select Language", ['a', 'b', 'e', 'f', 'h', 'i', 'p', 'z', 'j'])
95
-
96
  voice = st.selectbox("Select Voice", ['af_alloy', 'af_aoede', 'af_bella', 'af_heart', 'af_jessica', 'af_kore', 'af_nicole', 'af_nova', 'af_river', 'af_sarah', 'af_sky',
97
  'am_adam', 'am_echo', 'am_eric', 'am_fenrir', 'am_liam', 'am_michael', 'am_onyx', 'am_puck', 'am_santa',
98
  'bf_alice', 'bf_emma', 'bf_isabella', 'bf_lily',
@@ -109,8 +80,8 @@ voice = st.selectbox("Select Voice", ['af_alloy', 'af_aoede', 'af_bella', 'af_he
109
  'pf_dora',
110
  'pm_alex', 'pm_santa',
111
  'zf_xiaobei', 'zf_xiaoni', 'zf_xiaoxiao', 'zf_xiaoyi',
112
- 'zm_yunjian', 'zm_yunxi', 'zm_yunxia', 'zm_yunyang'])
113
-
114
  speed = st.slider("Speed", min_value=0.5, max_value=2.0, value=1.0, step=0.1)
115
 
116
  # Initialize the TTS pipeline with user-selected language
@@ -142,4 +113,4 @@ if st.button('Generate Audio'):
142
  data=audio_buffer,
143
  file_name="generated_speech.wav",
144
  mime="audio/wav"
145
- )
 
3
  import soundfile as sf
4
  import io
5
  import os
 
6
 
7
  # Install espeak-ng if not installed
8
  if not os.system("which espeak-ng"):
 
13
 
14
  # Streamlit App UI Setup
15
  st.title("Text-to-Speech with Kokoro")
 
16
  # Expander section to display information in multiple languages
17
  with st.expander("Sample Prompt!"):
18
  st.markdown("""
 
25
  - 我叫苏赫德夫。(In Chinese)
26
  - 私の名前はスクデフです。(In Japanese)
27
  """)
 
28
  st.sidebar.header("Configuration & Instructions")
29
 
30
  # Sidebar Instructions
 
61
  ### Courtesy: [Kokoro](https://huggingface.co/hexgrad/Kokoro-82M?fbclid=IwY2xjawIKqzxleHRuA2FlbQIxMAABHaf9GldgYOzXktNuoRtNKqd-aL7r-S7zPGyC8ttYOiG2zYfQqLyV4Qm75A_aem_0wKLC2C87ZZ2F04WjPJbtA)
62
  """)
63
 
 
 
 
 
 
 
 
 
 
64
  # User input for text, language, and voice settings
65
  input_text = st.text_area("Enter your text here", placeholder="The sky above the port was the color of television...")
66
+ lang_code = st.selectbox("Select Language", ['a', 'b', 'e', 'f', 'h', 'i', 'p', 'z', 'j'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  voice = st.selectbox("Select Voice", ['af_alloy', 'af_aoede', 'af_bella', 'af_heart', 'af_jessica', 'af_kore', 'af_nicole', 'af_nova', 'af_river', 'af_sarah', 'af_sky',
68
  'am_adam', 'am_echo', 'am_eric', 'am_fenrir', 'am_liam', 'am_michael', 'am_onyx', 'am_puck', 'am_santa',
69
  'bf_alice', 'bf_emma', 'bf_isabella', 'bf_lily',
 
80
  'pf_dora',
81
  'pm_alex', 'pm_santa',
82
  'zf_xiaobei', 'zf_xiaoni', 'zf_xiaoxiao', 'zf_xiaoyi',
83
+ 'zm_yunjian', 'zm_yunxi', 'zm_yunxia', 'zm_yunyang']
84
+ ) # Change voice options as per model
85
  speed = st.slider("Speed", min_value=0.5, max_value=2.0, value=1.0, step=0.1)
86
 
87
  # Initialize the TTS pipeline with user-selected language
 
113
  data=audio_buffer,
114
  file_name="generated_speech.wav",
115
  mime="audio/wav"
116
+ )