huazizai commited on
Commit
590895b
·
verified ·
1 Parent(s): 375db35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -19
app.py CHANGED
@@ -166,7 +166,7 @@ if __name__ == "__main__":
166
  model = ONNXVITS_infer.SynthesizerTrn(
167
  len(hps.symbols),
168
  hps.data.filter_length // 2 + 1,
169
- hps.train.segment_size // hps.data.hop_length,
170
  n_speakers=hps.data.n_speakers,
171
  ONNX_dir=onnx_dir,
172
  **hps.model)
@@ -218,28 +218,39 @@ if __name__ == "__main__":
218
  outputs=[textbox, temp_text_var]
219
  )
220
 
 
 
 
 
 
 
221
  symbol_list.select(
222
- fn=None,
223
- inputs=[symbol_list, symbol_list_json],
224
  outputs=textbox,
225
- _js="""
226
- function (evt, symbols, text) {
227
- const i = evt.index[0];
228
- const text_input = document.querySelector("#tts-input textarea");
229
- const startPos = text_input.selectionStart;
230
- const endPos = text_input.selectionEnd;
231
- const oldTxt = text_input.value;
232
- const symbol = symbols[i];
233
- const result = oldTxt.substring(0, startPos) + symbol + oldTxt.substring(endPos);
234
- text_input.value = result;
235
- text_input.focus();
236
- text_input.selectionStart = startPos + symbol.length;
237
- text_input.selectionEnd = startPos + symbol.length;
238
- return result;
239
- }
240
- """
241
  )
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  char_dropdown = gr.Dropdown(
244
  choices=speakers,
245
  value=speakers[0],
 
166
  model = ONNXVITS_infer.SynthesizerTrn(
167
  len(hps.symbols),
168
  hps.data.filter_length // 2 + 1,
169
+ hps.data.sampling_rate // hps.data.hop_length,
170
  n_speakers=hps.data.n_speakers,
171
  ONNX_dir=onnx_dir,
172
  **hps.model)
 
218
  outputs=[textbox, temp_text_var]
219
  )
220
 
221
+ def update_text(evt, symbols):
222
+ if not evt or not evt.index:
223
+ return None
224
+ i = evt.index[0]
225
+ return symbols[i]
226
+
227
  symbol_list.select(
228
+ fn=update_text,
229
+ inputs=[symbol_list_json],
230
  outputs=textbox,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  )
232
 
233
+ app.load(None, None, None, _js="""
234
+ function() {
235
+ document.addEventListener('gradio_select', function(e) {
236
+ if (e.target && e.target.id && e.target.id.includes('symbol-list')) {
237
+ const text_input = document.querySelector("#tts-input textarea");
238
+ if (text_input) {
239
+ const startPos = text_input.selectionStart;
240
+ const endPos = text_input.selectionEnd;
241
+ const oldTxt = text_input.value;
242
+ const symbol = e.detail.value;
243
+ const result = oldTxt.substring(0, startPos) + symbol + oldTxt.substring(endPos);
244
+ text_input.value = result;
245
+ text_input.focus();
246
+ text_input.selectionStart = startPos + symbol.length;
247
+ text_input.selectionEnd = startPos + symbol.length;
248
+ }
249
+ }
250
+ });
251
+ }
252
+ """)
253
+
254
  char_dropdown = gr.Dropdown(
255
  choices=speakers,
256
  value=speakers[0],