skytnt commited on
Commit
7ad7315
β€’
1 Parent(s): 35b7ab4

fix tts input auto scrolling

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -180,13 +180,7 @@ if __name__ == '__main__':
180
 
181
  with app:
182
  gr.Markdown("# Moe TTS And Voice Conversion Using VITS Model\n\n"
183
- "![visitor badge](https://visitor-badge.glitch.me/badge?page_id=skytnt.moegoe)\n\n"
184
- "unofficial demo for \n\n"
185
- "- [https://github.com/CjangCjengh/MoeGoe](https://github.com/CjangCjengh/MoeGoe)\n"
186
- "- [https://github.com/Francis-Komizu/VITS](https://github.com/Francis-Komizu/VITS)\n"
187
- "- [https://github.com/luoyily/MoeTTS](https://github.com/luoyily/MoeTTS)\n"
188
- "- [https://github.com/Francis-Komizu/Sovits](https://github.com/Francis-Komizu/Sovits)"
189
- )
190
  with gr.Tabs():
191
  with gr.TabItem("TTS"):
192
  with gr.Tabs():
@@ -206,7 +200,8 @@ if __name__ == '__main__':
206
  phoneme_input = gr.Checkbox(value=False, label="Phoneme input")
207
  to_phoneme_btn = gr.Button("Covert text to phoneme")
208
  phoneme_list = gr.Dataset(label="Phoneme list", components=[tts_input1],
209
- samples=[[x] for x in symbols])
 
210
  phoneme_list_json = gr.Json(value=symbols, visible=False)
211
  tts_submit = gr.Button("Generate", variant="primary")
212
  tts_output1 = gr.Textbox(label="Output Message")
@@ -217,19 +212,22 @@ if __name__ == '__main__':
217
  phoneme_list.click(None, [phoneme_list, phoneme_list_json], [],
218
  _js=f"""
219
  (i,phonemes) => {{
220
- let text_input = document.querySelector("body > gradio-app");
221
- if (text_input.shadowRoot != null)
222
- text_input = text_input.shadowRoot;
223
- text_input = text_input.querySelector("#tts-input{i}").querySelector("textarea");
224
  let startPos = text_input.selectionStart;
225
  let endPos = text_input.selectionEnd;
226
  let oldTxt = text_input.value;
227
  let result = oldTxt.substring(0, startPos) + phonemes[i] + oldTxt.substring(endPos);
228
  text_input.value = result;
229
- text_input.focus()
 
230
  text_input.selectionStart = startPos + phonemes[i].length;
231
  text_input.selectionEnd = startPos + phonemes[i].length;
232
- text_input.blur()
 
 
233
  }}""")
234
 
235
  with gr.TabItem("Voice Conversion"):
@@ -269,4 +267,11 @@ if __name__ == '__main__':
269
  js="()=>[null,null]")
270
  vc_submit.click(soft_vc_fn, [vc_input1, vc_input2, vc_input3],
271
  [vc_output1, vc_output2])
 
 
 
 
 
 
 
272
  app.queue(concurrency_count=3).launch(show_api=False)
 
180
 
181
  with app:
182
  gr.Markdown("# Moe TTS And Voice Conversion Using VITS Model\n\n"
183
+ "![visitor badge](https://visitor-badge.glitch.me/badge?page_id=skytnt.moegoe)\n\n")
 
 
 
 
 
 
184
  with gr.Tabs():
185
  with gr.TabItem("TTS"):
186
  with gr.Tabs():
 
200
  phoneme_input = gr.Checkbox(value=False, label="Phoneme input")
201
  to_phoneme_btn = gr.Button("Covert text to phoneme")
202
  phoneme_list = gr.Dataset(label="Phoneme list", components=[tts_input1],
203
+ samples=[[x] for x in symbols],
204
+ elem_id=f"phoneme-list{i}")
205
  phoneme_list_json = gr.Json(value=symbols, visible=False)
206
  tts_submit = gr.Button("Generate", variant="primary")
207
  tts_output1 = gr.Textbox(label="Output Message")
 
212
  phoneme_list.click(None, [phoneme_list, phoneme_list_json], [],
213
  _js=f"""
214
  (i,phonemes) => {{
215
+ let root = document.querySelector("body > gradio-app");
216
+ if (root.shadowRoot != null)
217
+ root = root.shadowRoot;
218
+ let text_input = root.querySelector("#tts-input{i}").querySelector("textarea");
219
  let startPos = text_input.selectionStart;
220
  let endPos = text_input.selectionEnd;
221
  let oldTxt = text_input.value;
222
  let result = oldTxt.substring(0, startPos) + phonemes[i] + oldTxt.substring(endPos);
223
  text_input.value = result;
224
+ let x = window.scrollX, y = window.scrollY;
225
+ text_input.focus();
226
  text_input.selectionStart = startPos + phonemes[i].length;
227
  text_input.selectionEnd = startPos + phonemes[i].length;
228
+ text_input.blur();
229
+ window.scrollTo(x, y);
230
+ return [];
231
  }}""")
232
 
233
  with gr.TabItem("Voice Conversion"):
 
267
  js="()=>[null,null]")
268
  vc_submit.click(soft_vc_fn, [vc_input1, vc_input2, vc_input3],
269
  [vc_output1, vc_output2])
270
+ gr.Markdown(
271
+ "unofficial demo for \n\n"
272
+ "- [https://github.com/CjangCjengh/MoeGoe](https://github.com/CjangCjengh/MoeGoe)\n"
273
+ "- [https://github.com/Francis-Komizu/VITS](https://github.com/Francis-Komizu/VITS)\n"
274
+ "- [https://github.com/luoyily/MoeTTS](https://github.com/luoyily/MoeTTS)\n"
275
+ "- [https://github.com/Francis-Komizu/Sovits](https://github.com/Francis-Komizu/Sovits)"
276
+ )
277
  app.queue(concurrency_count=3).launch(show_api=False)