nanaoto commited on
Commit
00ddf0a
·
1 Parent(s): 7b04ed4

feat: 归一化参数到推荐的范围,改善用户体验

Browse files

Former-commit-id: 2cd1f6c85307b56379142aa42161f5f03840298a [formerly af2b06e061937d291e276a0aa1bd4a2254a06078]
Former-commit-id: 7a27fb098872966e983ee96d4da1d46963e98600
Former-commit-id: a55065ba98ce67943c308424384f0bb762890f55 [formerly d6c5d012f7c18b046a4d5f0eb18c2f89e0d313c8] [formerly 028eb2cfa27072f21debffc392163c7c203be201 [formerly de7fd745561dd46d317159440cd07f021be3c4bc]]
Former-commit-id: 6720932ba30826158ba79aa63408e7270d8931e7 [formerly c569b751edfe4b50f211df2718be8303254af401]
Former-commit-id: 2b55f889408c2e440b06fafdcddd5300bf2a79ad

examples/cases.jsonl CHANGED
@@ -4,9 +4,9 @@
4
  {"prompt_audio":"voice_04.wav","text":"你就需要我这种专业人士的帮助,就像手无缚鸡之力的人进入雪山狩猎,一定需要最老练的猎人指导。","emo_mode":0}
5
  {"prompt_audio":"voice_05.wav","text":"在真正的日本剑道中,格斗过程极其短暂,常常短至半秒,最长也不超过两秒,利剑相击的转瞬间,已有一方倒在血泊中。但在这电光石火的对决之前,双方都要以一个石雕般凝固的姿势站定,长时间的逼视对方,这一过程可能长达十分钟!","emo_mode":0}
6
  {"prompt_audio":"voice_06.wav","text":"今天呢,咱们开一部新书,叫《赛博朋克二零七七》。这词儿我听着都新鲜。这赛博朋克啊,简单理解就是“高科技,低生活”。这一听,我就明白了,于老师就爱用那高科技的东西,手机都得拿脚纹开,大冬天为了解锁脱得一丝不挂,冻得跟王八蛋似的。","emo_mode":0}
7
- {"prompt_audio":"voice_07.wav","emo_audio":"emo_sad.wav","emo_weight": 0.9, "emo_mode":1,"text":"酒楼丧尽天良,开始借机竞拍房间,哎,一群蠢货。"}
8
- {"prompt_audio":"voice_08.wav","emo_audio":"emo_hate.wav","emo_weight": 0.8, "emo_mode":1,"text":"你看看你,对我还有没有一点父子之间的信任了。"}
9
- {"prompt_audio":"voice_09.wav","emo_vec_3":0.55,"emo_mode":2,"text":"对不起嘛!我的记性真的不太好,但是和你在一起的事情,我都会努力记住的~"}
10
- {"prompt_audio":"voice_10.wav","emo_vec_7":0.45,"emo_mode":2,"text":"哇塞!这个爆率也太高了!欧皇附体了!"}
11
  {"prompt_audio":"voice_11.wav","emo_mode":3,"emo_text":"极度悲伤","text":"这些年的时光终究是错付了... "}
12
  {"prompt_audio":"voice_12.wav","emo_mode":3,"emo_text":"You scared me to death! What are you, a ghost?","text":"快躲起来!是他要来了!他要来抓我们了!"}
 
4
  {"prompt_audio":"voice_04.wav","text":"你就需要我这种专业人士的帮助,就像手无缚鸡之力的人进入雪山狩猎,一定需要最老练的猎人指导。","emo_mode":0}
5
  {"prompt_audio":"voice_05.wav","text":"在真正的日本剑道中,格斗过程极其短暂,常常短至半秒,最长也不超过两秒,利剑相击的转瞬间,已有一方倒在血泊中。但在这电光石火的对决之前,双方都要以一个石雕般凝固的姿势站定,长时间的逼视对方,这一过程可能长达十分钟!","emo_mode":0}
6
  {"prompt_audio":"voice_06.wav","text":"今天呢,咱们开一部新书,叫《赛博朋克二零七七》。这词儿我听着都新鲜。这赛博朋克啊,简单理解就是“高科技,低生活”。这一听,我就明白了,于老师就爱用那高科技的东西,手机都得拿脚纹开,大冬天为了解锁脱得一丝不挂,冻得跟王八蛋似的。","emo_mode":0}
7
+ {"prompt_audio":"voice_07.wav","emo_audio":"emo_sad.wav","emo_weight": 1.0, "emo_mode":1,"text":"酒楼丧尽天良,开始借机竞拍房间,哎,一群蠢货。"}
8
+ {"prompt_audio":"voice_08.wav","emo_audio":"emo_hate.wav","emo_weight": 1.0, "emo_mode":1,"text":"你看看你,对我还有没有一点父子之间的信任了。"}
9
+ {"prompt_audio":"voice_09.wav","emo_vec_3":0.8,"emo_mode":2,"text":"对不起嘛!我的记性真的不太好,但是和你在一起的事情,我都会努力记住的~"}
10
+ {"prompt_audio":"voice_10.wav","emo_vec_7":1.0,"emo_mode":2,"text":"哇塞!这个爆率也太高了!欧皇附体了!"}
11
  {"prompt_audio":"voice_11.wav","emo_mode":3,"emo_text":"极度悲伤","text":"这些年的时光终究是错付了... "}
12
  {"prompt_audio":"voice_12.wav","emo_mode":3,"emo_text":"You scared me to death! What are you, a ghost?","text":"快躲起来!是他要来了!他要来抓我们了!"}
tools/i18n/locale/en_US.json CHANGED
@@ -42,7 +42,8 @@
42
  "请上传情感参考音频": "Please upload the emotion reference audio",
43
  "当前模型版本": "Current model version: ",
44
  "请输入目标文本": "Please input the text to synthesize",
45
- "例如:高兴,愤怒,悲伤等": "e.g., happy, angry, sad, etc.",
46
  "与音色参考音频相同": "Same as the voice reference",
47
- "情感随机采样": "Randomize emotion sampling"
 
48
  }
 
42
  "请上传情感参考音频": "Please upload the emotion reference audio",
43
  "当前模型版本": "Current model version: ",
44
  "请输入目标文本": "Please input the text to synthesize",
45
+ "例如:委屈巴巴、危险在悄悄逼近": "e.g. deeply sad, danger is creeping closer",
46
  "与音色参考音频相同": "Same as the voice reference",
47
+ "情感随机采样": "Randomize emotion sampling",
48
+ "显示实验功能": "Show experimental features"
49
  }
tools/i18n/locale/zh_CN.json CHANGED
@@ -38,5 +38,7 @@
38
  "GPT2 采样设置": "GPT2 采样设置",
39
  "参数会影响音频多样性和生成速度详见": "参数会影响音频多样性和生成速度详见",
40
  "是否进行采样": "是否进行采样",
41
- "生成Token最大数量,过小导致音频被截断": "生成Token最大数量,过小导致音频被截断"
 
 
42
  }
 
38
  "GPT2 采样设置": "GPT2 采样设置",
39
  "参数会影响音频多样性和生成速度详见": "参数会影响音频多样性和生成速度详见",
40
  "是否进行采样": "是否进行采样",
41
+ "生成Token最大数量,过小导致音频被截断": "生成Token最大数量,过小导致音频被截断",
42
+ "显示实验功能": "显示实验功能",
43
+ "例如:委屈巴巴、危险在悄悄逼近": "例如:委屈巴巴、危险在悄悄逼近"
44
  }
webui.py CHANGED
@@ -6,6 +6,8 @@ import time
6
 
7
  import warnings
8
 
 
 
9
  warnings.filterwarnings("ignore", category=FutureWarning)
10
  warnings.filterwarnings("ignore", category=UserWarning)
11
 
@@ -67,6 +69,9 @@ EMO_CHOICES = [i18n("与音色参考音频相同"),
67
  i18n("使用情感参考音频"),
68
  i18n("使用情感向量控制"),
69
  i18n("使用情感描述文本控制")]
 
 
 
70
  os.makedirs("outputs/tasks",exist_ok=True)
71
  os.makedirs("prompts",exist_ok=True)
72
 
@@ -95,9 +100,17 @@ with open("examples/cases.jsonl", "r", encoding="utf-8") as f:
95
  example.get("emo_vec_5",0),
96
  example.get("emo_vec_6",0),
97
  example.get("emo_vec_7",0),
98
- example.get("emo_vec_8",0)]
 
99
  )
100
 
 
 
 
 
 
 
 
101
 
102
  def gen_single(emo_control_method,prompt, text,
103
  emo_ref_path, emo_weight,
@@ -128,15 +141,13 @@ def gen_single(emo_control_method,prompt, text,
128
  emo_control_method = emo_control_method.value
129
  if emo_control_method == 0: # emotion from speaker
130
  emo_ref_path = None # remove external reference audio
131
- emo_weight = 1.0
132
  if emo_control_method == 1: # emotion from reference audio
133
- # emo_weight = emo_weight
 
134
  pass
135
  if emo_control_method == 2: # emotion from custom vectors
136
  vec = [vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8]
137
- if sum(vec) > 1.5:
138
- gr.Warning(i18n("情感向量之和不能超过1.5,请调整后重试。"))
139
- return
140
  else:
141
  # don't use the emotion vector inputs for the other modes
142
  vec = None
@@ -182,13 +193,14 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
182
  input_text_single = gr.TextArea(label=i18n("文本"),key="input_text_single", placeholder=i18n("请输入目标文本"), info=f"{i18n('当前模型版本')}{tts.model_version or '1.0'}")
183
  gen_button = gr.Button(i18n("生成语音"), key="gen_button",interactive=True)
184
  output_audio = gr.Audio(label=i18n("生成结果"), visible=True,key="output_audio")
 
185
  with gr.Accordion(i18n("功能设置")):
186
  # 情感控制选项部分
187
  with gr.Row():
188
  emo_control_method = gr.Radio(
189
- choices=EMO_CHOICES,
190
  type="index",
191
- value=EMO_CHOICES[0],label=i18n("情感控制方式"))
192
  # 情感参考音频部分
193
  with gr.Group(visible=False) as emotion_reference_group:
194
  with gr.Row():
@@ -202,24 +214,28 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
202
  with gr.Group(visible=False) as emotion_vector_group:
203
  with gr.Row():
204
  with gr.Column():
205
- vec1 = gr.Slider(label=i18n("喜"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
206
- vec2 = gr.Slider(label=i18n("怒"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
207
- vec3 = gr.Slider(label=i18n("哀"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
208
- vec4 = gr.Slider(label=i18n("惧"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
209
  with gr.Column():
210
- vec5 = gr.Slider(label=i18n("厌恶"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
211
- vec6 = gr.Slider(label=i18n("低落"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
212
- vec7 = gr.Slider(label=i18n("惊喜"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
213
- vec8 = gr.Slider(label=i18n("平静"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
214
 
215
  with gr.Group(visible=False) as emo_text_group:
216
  with gr.Row():
217
- emo_text = gr.Textbox(label=i18n("情感描述文本"), placeholder=i18n("请输入情绪描述(或留空以自动使用目标文本作为情绪描述)"), value="", info=i18n("例如:高兴,愤怒,悲伤等"))
 
 
 
 
218
 
219
  with gr.Row(visible=False) as emo_weight_group:
220
- emo_weight = gr.Slider(label=i18n("情感权重"), minimum=0.0, maximum=1.6, value=0.8, step=0.01)
221
 
222
- with gr.Accordion(i18n("高级生成参数设置"), open=False):
223
  with gr.Row():
224
  with gr.Column(scale=1):
225
  gr.Markdown(f"**{i18n('GPT2 采样设置')}** _{i18n('参数会影响音频多样性和生成速度详见')} [Generation strategies](https://huggingface.co/docs/transformers/main/en/generation_strategies)._")
@@ -257,8 +273,20 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
257
  # typical_sampling, typical_mass,
258
  ]
259
 
260
- if len(example_cases) > 0:
261
- gr.Examples(
 
 
 
 
 
 
 
 
 
 
 
 
262
  examples=example_cases,
263
  examples_per_page=20,
264
  inputs=[prompt_audio,
@@ -267,7 +295,7 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
267
  emo_upload,
268
  emo_weight,
269
  emo_text,
270
- vec1,vec2,vec3,vec4,vec5,vec6,vec7,vec8]
271
  )
272
 
273
  def on_input_text_change(text, max_text_tokens_per_segment):
@@ -288,6 +316,7 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
288
  return {
289
  segments_preview: gr.update(value=df),
290
  }
 
291
  def on_method_select(emo_control_method):
292
  if emo_control_method == 1: # emotion reference audio
293
  return (gr.update(visible=True),
@@ -301,7 +330,7 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
301
  gr.update(visible=True),
302
  gr.update(visible=True),
303
  gr.update(visible=False),
304
- gr.update(visible=True)
305
  )
306
  elif emo_control_method == 3: # emotion text description
307
  return (gr.update(visible=False),
@@ -318,6 +347,14 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
318
  gr.update(visible=False)
319
  )
320
 
 
 
 
 
 
 
 
 
321
  emo_control_method.select(on_method_select,
322
  inputs=[emo_control_method],
323
  outputs=[emotion_reference_group,
@@ -332,11 +369,19 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
332
  inputs=[input_text_single, max_text_tokens_per_segment],
333
  outputs=[segments_preview]
334
  )
 
 
 
 
 
 
 
335
  max_text_tokens_per_segment.change(
336
  on_input_text_change,
337
  inputs=[input_text_single, max_text_tokens_per_segment],
338
  outputs=[segments_preview]
339
  )
 
340
  prompt_audio.upload(update_prompt_audio,
341
  inputs=[],
342
  outputs=[gen_button])
 
6
 
7
  import warnings
8
 
9
+ import numpy as np
10
+
11
  warnings.filterwarnings("ignore", category=FutureWarning)
12
  warnings.filterwarnings("ignore", category=UserWarning)
13
 
 
69
  i18n("使用情感参考音频"),
70
  i18n("使用情感向量控制"),
71
  i18n("使用情感描述文本控制")]
72
+ EMO_CHOICES_BASE = EMO_CHOICES[:3] # 基础选项
73
+ EMO_CHOICES_EXPERIMENTAL = EMO_CHOICES # 全部选项(包括文本描述)
74
+
75
  os.makedirs("outputs/tasks",exist_ok=True)
76
  os.makedirs("prompts",exist_ok=True)
77
 
 
100
  example.get("emo_vec_5",0),
101
  example.get("emo_vec_6",0),
102
  example.get("emo_vec_7",0),
103
+ example.get("emo_vec_8",0),
104
+ example.get("emo_text") is not None]
105
  )
106
 
107
+ def normalize_emo_vec(emo_vec):
108
+ # emotion factors for better user experience
109
+ k_vec = [0.75,0.70,0.80,0.80,0.75,0.75,0.55,0.45]
110
+ tmp = np.array(k_vec) * np.array(emo_vec)
111
+ if np.sum(tmp) > 0.8:
112
+ tmp = tmp * 0.8/ np.sum(tmp)
113
+ return tmp.tolist()
114
 
115
  def gen_single(emo_control_method,prompt, text,
116
  emo_ref_path, emo_weight,
 
141
  emo_control_method = emo_control_method.value
142
  if emo_control_method == 0: # emotion from speaker
143
  emo_ref_path = None # remove external reference audio
 
144
  if emo_control_method == 1: # emotion from reference audio
145
+ # normalize emo_alpha for better user experience
146
+ emo_weight = emo_weight * 0.8
147
  pass
148
  if emo_control_method == 2: # emotion from custom vectors
149
  vec = [vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8]
150
+ vec = normalize_emo_vec(vec)
 
 
151
  else:
152
  # don't use the emotion vector inputs for the other modes
153
  vec = None
 
193
  input_text_single = gr.TextArea(label=i18n("文本"),key="input_text_single", placeholder=i18n("请输入目标文本"), info=f"{i18n('当前模型版本')}{tts.model_version or '1.0'}")
194
  gen_button = gr.Button(i18n("生成语音"), key="gen_button",interactive=True)
195
  output_audio = gr.Audio(label=i18n("生成结果"), visible=True,key="output_audio")
196
+ experimental_checkbox = gr.Checkbox(label=i18n("显示实验功能"),value=False)
197
  with gr.Accordion(i18n("功能设置")):
198
  # 情感控制选项部分
199
  with gr.Row():
200
  emo_control_method = gr.Radio(
201
+ choices=EMO_CHOICES_BASE,
202
  type="index",
203
+ value=EMO_CHOICES_BASE[0],label=i18n("情感控制方式"))
204
  # 情感参考音频部分
205
  with gr.Group(visible=False) as emotion_reference_group:
206
  with gr.Row():
 
214
  with gr.Group(visible=False) as emotion_vector_group:
215
  with gr.Row():
216
  with gr.Column():
217
+ vec1 = gr.Slider(label=i18n("喜"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
218
+ vec2 = gr.Slider(label=i18n("怒"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
219
+ vec3 = gr.Slider(label=i18n("哀"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
220
+ vec4 = gr.Slider(label=i18n("惧"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
221
  with gr.Column():
222
+ vec5 = gr.Slider(label=i18n("厌恶"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
223
+ vec6 = gr.Slider(label=i18n("低落"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
224
+ vec7 = gr.Slider(label=i18n("惊喜"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
225
+ vec8 = gr.Slider(label=i18n("平静"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
226
 
227
  with gr.Group(visible=False) as emo_text_group:
228
  with gr.Row():
229
+ emo_text = gr.Textbox(label=i18n("情感描述文本"),
230
+ placeholder=i18n("请输入情绪描述(或留空以自动使用目标文本作为情绪描述)"),
231
+ value="",
232
+ info=i18n("例如:委屈巴巴、危险在悄悄逼近"))
233
+
234
 
235
  with gr.Row(visible=False) as emo_weight_group:
236
+ emo_weight = gr.Slider(label=i18n("情感权重"), minimum=0.0, maximum=1.0, value=0.8, step=0.01)
237
 
238
+ with gr.Accordion(i18n("高级生成参数设置"), open=False,visible=False) as advanced_settings_group:
239
  with gr.Row():
240
  with gr.Column(scale=1):
241
  gr.Markdown(f"**{i18n('GPT2 采样设置')}** _{i18n('参数会影响音频多样性和生成速度详见')} [Generation strategies](https://huggingface.co/docs/transformers/main/en/generation_strategies)._")
 
273
  # typical_sampling, typical_mass,
274
  ]
275
 
276
+ if len(example_cases) > 2:
277
+ example_table = gr.Examples(
278
+ examples=example_cases[:-2],
279
+ examples_per_page=20,
280
+ inputs=[prompt_audio,
281
+ emo_control_method,
282
+ input_text_single,
283
+ emo_upload,
284
+ emo_weight,
285
+ emo_text,
286
+ vec1,vec2,vec3,vec4,vec5,vec6,vec7,vec8,experimental_checkbox]
287
+ )
288
+ elif len(example_cases) > 0:
289
+ example_table = gr.Examples(
290
  examples=example_cases,
291
  examples_per_page=20,
292
  inputs=[prompt_audio,
 
295
  emo_upload,
296
  emo_weight,
297
  emo_text,
298
+ vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, experimental_checkbox]
299
  )
300
 
301
  def on_input_text_change(text, max_text_tokens_per_segment):
 
316
  return {
317
  segments_preview: gr.update(value=df),
318
  }
319
+
320
  def on_method_select(emo_control_method):
321
  if emo_control_method == 1: # emotion reference audio
322
  return (gr.update(visible=True),
 
330
  gr.update(visible=True),
331
  gr.update(visible=True),
332
  gr.update(visible=False),
333
+ gr.update(visible=False)
334
  )
335
  elif emo_control_method == 3: # emotion text description
336
  return (gr.update(visible=False),
 
347
  gr.update(visible=False)
348
  )
349
 
350
+ def on_experimental_change(is_exp):
351
+ # 切换情感控制选项
352
+ # 第三个返回值实际没有起作用
353
+ if is_exp:
354
+ return gr.update(choices=EMO_CHOICES_EXPERIMENTAL, value=EMO_CHOICES_EXPERIMENTAL[0]), gr.update(visible=True),gr.update(value=example_cases)
355
+ else:
356
+ return gr.update(choices=EMO_CHOICES_BASE, value=EMO_CHOICES_BASE[0]), gr.update(visible=False),gr.update(value=example_cases[:-2])
357
+
358
  emo_control_method.select(on_method_select,
359
  inputs=[emo_control_method],
360
  outputs=[emotion_reference_group,
 
369
  inputs=[input_text_single, max_text_tokens_per_segment],
370
  outputs=[segments_preview]
371
  )
372
+
373
+ experimental_checkbox.change(
374
+ on_experimental_change,
375
+ inputs=[experimental_checkbox],
376
+ outputs=[emo_control_method, advanced_settings_group,example_table.dataset] # 高级参数Accordion
377
+ )
378
+
379
  max_text_tokens_per_segment.change(
380
  on_input_text_change,
381
  inputs=[input_text_single, max_text_tokens_per_segment],
382
  outputs=[segments_preview]
383
  )
384
+
385
  prompt_audio.upload(update_prompt_audio,
386
  inputs=[],
387
  outputs=[gen_button])