skytnt commited on
Commit
1b4fbf7
β€’
1 Parent(s): dfdeaec
Files changed (2) hide show
  1. app.py +19 -3
  2. text/cleaners.py +1 -1
app.py CHANGED
@@ -155,7 +155,8 @@ if __name__ == '__main__':
155
  gr.Markdown(f"## {name}\n\n"
156
  f"![cover](file/{cover_path})\n\n"
157
  f"lang: {lang}")
158
- tts_input1 = gr.TextArea(label="Text (60 words limitation)", value=example)
 
159
  tts_input2 = gr.Dropdown(label="Speaker", choices=speakers,
160
  type="index", value=speakers[0])
161
  tts_input3 = gr.Slider(label="Speed", value=1, minimum=0.5, maximum=2, step=0.1)
@@ -182,8 +183,23 @@ if __name__ == '__main__':
182
  tts_submit.click(tts_fn, [tts_input1, tts_input2, tts_input3, phoneme_input],
183
  [tts_output1, tts_output2])
184
  to_phoneme_btn.click(to_phoneme_fn, [tts_input1], [tts_input1])
185
- phoneme_list.click(None, [phoneme_list, phoneme_list_json, tts_input1], [tts_input1],
186
- _js="(i,phonemes, text) => text + phonemes[i]")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  with gr.TabItem("Voice Conversion"):
189
  with gr.Tabs():
 
155
  gr.Markdown(f"## {name}\n\n"
156
  f"![cover](file/{cover_path})\n\n"
157
  f"lang: {lang}")
158
+ tts_input1 = gr.TextArea(label="Text (60 words limitation)", value=example,
159
+ elem_id="tts-input")
160
  tts_input2 = gr.Dropdown(label="Speaker", choices=speakers,
161
  type="index", value=speakers[0])
162
  tts_input3 = gr.Slider(label="Speed", value=1, minimum=0.5, maximum=2, step=0.1)
 
183
  tts_submit.click(tts_fn, [tts_input1, tts_input2, tts_input3, phoneme_input],
184
  [tts_output1, tts_output2])
185
  to_phoneme_btn.click(to_phoneme_fn, [tts_input1], [tts_input1])
186
+ phoneme_list.click(None, [phoneme_list, phoneme_list_json], [],
187
+ _js="""
188
+ (i,phonemes) => {
189
+ let text_input = document.querySelector("body > gradio-app");
190
+ if (text_input.shadowRoot != null)
191
+ text_input = text_input.shadowRoot;
192
+ text_input = text_input.querySelector("#tts-input").querySelector("textarea");
193
+ let startPos = text_input.selectionStart;
194
+ let endPos = text_input.selectionEnd;
195
+ let oldTxt = text_input.value;
196
+ let result = oldTxt.substring(0, startPos) + phonemes[i] + oldTxt.substring(endPos);
197
+ text_input.value = result;
198
+ text_input.focus()
199
+ text_input.selectionStart = startPos + phonemes[i].length;
200
+ text_input.selectionEnd = startPos + phonemes[i].length;
201
+ text_input.blur()
202
+ }""")
203
 
204
  with gr.TabItem("Voice Conversion"):
205
  with gr.Tabs():
text/cleaners.py CHANGED
@@ -466,7 +466,7 @@ def chinese_cleaners(text):
466
  text = number_to_chinese(text)
467
  text = chinese_to_bopomofo(text)
468
  text = latin_to_bopomofo(text)
469
- if re.match('[Λ‰ΛŠΛ‡Λ‹Λ™]', text[-1]):
470
  text += '。'
471
  return text
472
 
 
466
  text = number_to_chinese(text)
467
  text = chinese_to_bopomofo(text)
468
  text = latin_to_bopomofo(text)
469
+ if len(text) > 0 and re.match('[Λ‰ΛŠΛ‡Λ‹Λ™]', text[-1]):
470
  text += '。'
471
  return text
472