mirror of
https://github.com/index-tts/index-tts.git
synced 2025-11-25 19:37:47 +08:00
feat: 归一化参数到推荐的范围,改善用户体验
This commit is contained in:
@@ -4,9 +4,9 @@
|
|||||||
{"prompt_audio":"voice_04.wav","text":"你就需要我这种专业人士的帮助,就像手无缚鸡之力的人进入雪山狩猎,一定需要最老练的猎人指导。","emo_mode":0}
|
{"prompt_audio":"voice_04.wav","text":"你就需要我这种专业人士的帮助,就像手无缚鸡之力的人进入雪山狩猎,一定需要最老练的猎人指导。","emo_mode":0}
|
||||||
{"prompt_audio":"voice_05.wav","text":"在真正的日本剑道中,格斗过程极其短暂,常常短至半秒,最长也不超过两秒,利剑相击的转瞬间,已有一方倒在血泊中。但在这电光石火的对决之前,双方都要以一个石雕般凝固的姿势站定,长时间的逼视对方,这一过程可能长达十分钟!","emo_mode":0}
|
{"prompt_audio":"voice_05.wav","text":"在真正的日本剑道中,格斗过程极其短暂,常常短至半秒,最长也不超过两秒,利剑相击的转瞬间,已有一方倒在血泊中。但在这电光石火的对决之前,双方都要以一个石雕般凝固的姿势站定,长时间的逼视对方,这一过程可能长达十分钟!","emo_mode":0}
|
||||||
{"prompt_audio":"voice_06.wav","text":"今天呢,咱们开一部新书,叫《赛博朋克二零七七》。这词儿我听着都新鲜。这赛博朋克啊,简单理解就是“高科技,低生活”。这一听,我就明白了,于老师就爱用那高科技的东西,手机都得拿脚纹开,大冬天为了解锁脱得一丝不挂,冻得跟王八蛋似的。","emo_mode":0}
|
{"prompt_audio":"voice_06.wav","text":"今天呢,咱们开一部新书,叫《赛博朋克二零七七》。这词儿我听着都新鲜。这赛博朋克啊,简单理解就是“高科技,低生活”。这一听,我就明白了,于老师就爱用那高科技的东西,手机都得拿脚纹开,大冬天为了解锁脱得一丝不挂,冻得跟王八蛋似的。","emo_mode":0}
|
||||||
{"prompt_audio":"voice_07.wav","emo_audio":"emo_sad.wav","emo_weight": 0.9, "emo_mode":1,"text":"酒楼丧尽天良,开始借机竞拍房间,哎,一群蠢货。"}
|
{"prompt_audio":"voice_07.wav","emo_audio":"emo_sad.wav","emo_weight": 1.0, "emo_mode":1,"text":"酒楼丧尽天良,开始借机竞拍房间,哎,一群蠢货。"}
|
||||||
{"prompt_audio":"voice_08.wav","emo_audio":"emo_hate.wav","emo_weight": 0.8, "emo_mode":1,"text":"你看看你,对我还有没有一点父子之间的信任了。"}
|
{"prompt_audio":"voice_08.wav","emo_audio":"emo_hate.wav","emo_weight": 1.0, "emo_mode":1,"text":"你看看你,对我还有没有一点父子之间的信任了。"}
|
||||||
{"prompt_audio":"voice_09.wav","emo_vec_3":0.55,"emo_mode":2,"text":"对不起嘛!我的记性真的不太好,但是和你在一起的事情,我都会努力记住的~"}
|
{"prompt_audio":"voice_09.wav","emo_vec_3":0.8,"emo_mode":2,"text":"对不起嘛!我的记性真的不太好,但是和你在一起的事情,我都会努力记住的~"}
|
||||||
{"prompt_audio":"voice_10.wav","emo_vec_7":0.45,"emo_mode":2,"text":"哇塞!这个爆率也太高了!欧皇附体了!"}
|
{"prompt_audio":"voice_10.wav","emo_vec_7":1.0,"emo_mode":2,"text":"哇塞!这个爆率也太高了!欧皇附体了!"}
|
||||||
{"prompt_audio":"voice_11.wav","emo_mode":3,"emo_text":"极度悲伤","text":"这些年的时光终究是错付了... "}
|
{"prompt_audio":"voice_11.wav","emo_mode":3,"emo_text":"极度悲伤","text":"这些年的时光终究是错付了... "}
|
||||||
{"prompt_audio":"voice_12.wav","emo_mode":3,"emo_text":"You scared me to death! What are you, a ghost?","text":"快躲起来!是他要来了!他要来抓我们了!"}
|
{"prompt_audio":"voice_12.wav","emo_mode":3,"emo_text":"You scared me to death! What are you, a ghost?","text":"快躲起来!是他要来了!他要来抓我们了!"}
|
||||||
@@ -42,7 +42,8 @@
|
|||||||
"请上传情感参考音频": "Please upload the emotion reference audio",
|
"请上传情感参考音频": "Please upload the emotion reference audio",
|
||||||
"当前模型版本": "Current model version: ",
|
"当前模型版本": "Current model version: ",
|
||||||
"请输入目标文本": "Please input the text to synthesize",
|
"请输入目标文本": "Please input the text to synthesize",
|
||||||
"例如:高兴,愤怒,悲伤等": "e.g., happy, angry, sad, etc.",
|
"例如:委屈巴巴、危险在悄悄逼近": "e.g. deeply sad, danger is creeping closer",
|
||||||
"与音色参考音频相同": "Same as the voice reference",
|
"与音色参考音频相同": "Same as the voice reference",
|
||||||
"情感随机采样": "Randomize emotion sampling"
|
"情感随机采样": "Randomize emotion sampling",
|
||||||
|
"显示实验功能": "Show experimental features"
|
||||||
}
|
}
|
||||||
@@ -38,5 +38,7 @@
|
|||||||
"GPT2 采样设置": "GPT2 采样设置",
|
"GPT2 采样设置": "GPT2 采样设置",
|
||||||
"参数会影响音频多样性和生成速度详见": "参数会影响音频多样性和生成速度详见",
|
"参数会影响音频多样性和生成速度详见": "参数会影响音频多样性和生成速度详见",
|
||||||
"是否进行采样": "是否进行采样",
|
"是否进行采样": "是否进行采样",
|
||||||
"生成Token最大数量,过小导致音频被截断": "生成Token最大数量,过小导致音频被截断"
|
"生成Token最大数量,过小导致音频被截断": "生成Token最大数量,过小导致音频被截断",
|
||||||
|
"显示实验功能": "显示实验功能",
|
||||||
|
"例如:委屈巴巴、危险在悄悄逼近": "例如:委屈巴巴、危险在悄悄逼近"
|
||||||
}
|
}
|
||||||
91
webui.py
91
webui.py
@@ -6,6 +6,8 @@ import time
|
|||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
warnings.filterwarnings("ignore", category=FutureWarning)
|
warnings.filterwarnings("ignore", category=FutureWarning)
|
||||||
warnings.filterwarnings("ignore", category=UserWarning)
|
warnings.filterwarnings("ignore", category=UserWarning)
|
||||||
|
|
||||||
@@ -67,6 +69,9 @@ EMO_CHOICES = [i18n("与音色参考音频相同"),
|
|||||||
i18n("使用情感参考音频"),
|
i18n("使用情感参考音频"),
|
||||||
i18n("使用情感向量控制"),
|
i18n("使用情感向量控制"),
|
||||||
i18n("使用情感描述文本控制")]
|
i18n("使用情感描述文本控制")]
|
||||||
|
EMO_CHOICES_BASE = EMO_CHOICES[:3] # 基础选项
|
||||||
|
EMO_CHOICES_EXPERIMENTAL = EMO_CHOICES # 全部选项(包括文本描述)
|
||||||
|
|
||||||
os.makedirs("outputs/tasks",exist_ok=True)
|
os.makedirs("outputs/tasks",exist_ok=True)
|
||||||
os.makedirs("prompts",exist_ok=True)
|
os.makedirs("prompts",exist_ok=True)
|
||||||
|
|
||||||
@@ -95,9 +100,17 @@ with open("examples/cases.jsonl", "r", encoding="utf-8") as f:
|
|||||||
example.get("emo_vec_5",0),
|
example.get("emo_vec_5",0),
|
||||||
example.get("emo_vec_6",0),
|
example.get("emo_vec_6",0),
|
||||||
example.get("emo_vec_7",0),
|
example.get("emo_vec_7",0),
|
||||||
example.get("emo_vec_8",0)]
|
example.get("emo_vec_8",0),
|
||||||
|
example.get("emo_text") is not None]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def normalize_emo_vec(emo_vec):
|
||||||
|
# emotion factors for better user experience
|
||||||
|
k_vec = [0.75,0.70,0.80,0.80,0.75,0.75,0.55,0.45]
|
||||||
|
tmp = np.array(k_vec) * np.array(emo_vec)
|
||||||
|
if np.sum(tmp) > 0.8:
|
||||||
|
tmp = tmp * 0.8/ np.sum(tmp)
|
||||||
|
return tmp.tolist()
|
||||||
|
|
||||||
def gen_single(emo_control_method,prompt, text,
|
def gen_single(emo_control_method,prompt, text,
|
||||||
emo_ref_path, emo_weight,
|
emo_ref_path, emo_weight,
|
||||||
@@ -128,15 +141,13 @@ def gen_single(emo_control_method,prompt, text,
|
|||||||
emo_control_method = emo_control_method.value
|
emo_control_method = emo_control_method.value
|
||||||
if emo_control_method == 0: # emotion from speaker
|
if emo_control_method == 0: # emotion from speaker
|
||||||
emo_ref_path = None # remove external reference audio
|
emo_ref_path = None # remove external reference audio
|
||||||
emo_weight = 1.0
|
|
||||||
if emo_control_method == 1: # emotion from reference audio
|
if emo_control_method == 1: # emotion from reference audio
|
||||||
# emo_weight = emo_weight
|
# normalize emo_alpha for better user experience
|
||||||
|
emo_weight = emo_weight * 0.8
|
||||||
pass
|
pass
|
||||||
if emo_control_method == 2: # emotion from custom vectors
|
if emo_control_method == 2: # emotion from custom vectors
|
||||||
vec = [vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8]
|
vec = [vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8]
|
||||||
if sum(vec) > 1.5:
|
vec = normalize_emo_vec(vec)
|
||||||
gr.Warning(i18n("情感向量之和不能超过1.5,请调整后重试。"))
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
# don't use the emotion vector inputs for the other modes
|
# don't use the emotion vector inputs for the other modes
|
||||||
vec = None
|
vec = None
|
||||||
@@ -182,13 +193,14 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
|
|||||||
input_text_single = gr.TextArea(label=i18n("文本"),key="input_text_single", placeholder=i18n("请输入目标文本"), info=f"{i18n('当前模型版本')}{tts.model_version or '1.0'}")
|
input_text_single = gr.TextArea(label=i18n("文本"),key="input_text_single", placeholder=i18n("请输入目标文本"), info=f"{i18n('当前模型版本')}{tts.model_version or '1.0'}")
|
||||||
gen_button = gr.Button(i18n("生成语音"), key="gen_button",interactive=True)
|
gen_button = gr.Button(i18n("生成语音"), key="gen_button",interactive=True)
|
||||||
output_audio = gr.Audio(label=i18n("生成结果"), visible=True,key="output_audio")
|
output_audio = gr.Audio(label=i18n("生成结果"), visible=True,key="output_audio")
|
||||||
|
experimental_checkbox = gr.Checkbox(label=i18n("显示实验功能"),value=False)
|
||||||
with gr.Accordion(i18n("功能设置")):
|
with gr.Accordion(i18n("功能设置")):
|
||||||
# 情感控制选项部分
|
# 情感控制选项部分
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
emo_control_method = gr.Radio(
|
emo_control_method = gr.Radio(
|
||||||
choices=EMO_CHOICES,
|
choices=EMO_CHOICES_BASE,
|
||||||
type="index",
|
type="index",
|
||||||
value=EMO_CHOICES[0],label=i18n("情感控制方式"))
|
value=EMO_CHOICES_BASE[0],label=i18n("情感控制方式"))
|
||||||
# 情感参考音频部分
|
# 情感参考音频部分
|
||||||
with gr.Group(visible=False) as emotion_reference_group:
|
with gr.Group(visible=False) as emotion_reference_group:
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
@@ -202,24 +214,28 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
|
|||||||
with gr.Group(visible=False) as emotion_vector_group:
|
with gr.Group(visible=False) as emotion_vector_group:
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
vec1 = gr.Slider(label=i18n("喜"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
|
vec1 = gr.Slider(label=i18n("喜"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
|
||||||
vec2 = gr.Slider(label=i18n("怒"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
|
vec2 = gr.Slider(label=i18n("怒"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
|
||||||
vec3 = gr.Slider(label=i18n("哀"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
|
vec3 = gr.Slider(label=i18n("哀"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
|
||||||
vec4 = gr.Slider(label=i18n("惧"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
|
vec4 = gr.Slider(label=i18n("惧"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
vec5 = gr.Slider(label=i18n("厌恶"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
|
vec5 = gr.Slider(label=i18n("厌恶"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
|
||||||
vec6 = gr.Slider(label=i18n("低落"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
|
vec6 = gr.Slider(label=i18n("低落"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
|
||||||
vec7 = gr.Slider(label=i18n("惊喜"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
|
vec7 = gr.Slider(label=i18n("惊喜"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
|
||||||
vec8 = gr.Slider(label=i18n("平静"), minimum=0.0, maximum=1.4, value=0.0, step=0.05)
|
vec8 = gr.Slider(label=i18n("平静"), minimum=0.0, maximum=1.0, value=0.0, step=0.05)
|
||||||
|
|
||||||
with gr.Group(visible=False) as emo_text_group:
|
with gr.Group(visible=False) as emo_text_group:
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
emo_text = gr.Textbox(label=i18n("情感描述文本"), placeholder=i18n("请输入情绪描述(或留空以自动使用目标文本作为情绪描述)"), value="", info=i18n("例如:高兴,愤怒,悲伤等"))
|
emo_text = gr.Textbox(label=i18n("情感描述文本"),
|
||||||
|
placeholder=i18n("请输入情绪描述(或留空以自动使用目标文本作为情绪描述)"),
|
||||||
|
value="",
|
||||||
|
info=i18n("例如:委屈巴巴、危险在悄悄逼近"))
|
||||||
|
|
||||||
|
|
||||||
with gr.Row(visible=False) as emo_weight_group:
|
with gr.Row(visible=False) as emo_weight_group:
|
||||||
emo_weight = gr.Slider(label=i18n("情感权重"), minimum=0.0, maximum=1.6, value=0.8, step=0.01)
|
emo_weight = gr.Slider(label=i18n("情感权重"), minimum=0.0, maximum=1.0, value=0.8, step=0.01)
|
||||||
|
|
||||||
with gr.Accordion(i18n("高级生成参数设置"), open=False):
|
with gr.Accordion(i18n("高级生成参数设置"), open=False,visible=False) as advanced_settings_group:
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
with gr.Column(scale=1):
|
with gr.Column(scale=1):
|
||||||
gr.Markdown(f"**{i18n('GPT2 采样设置')}** _{i18n('参数会影响音频多样性和生成速度详见')} [Generation strategies](https://huggingface.co/docs/transformers/main/en/generation_strategies)._")
|
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:
|
|||||||
# typical_sampling, typical_mass,
|
# typical_sampling, typical_mass,
|
||||||
]
|
]
|
||||||
|
|
||||||
if len(example_cases) > 0:
|
if len(example_cases) > 2:
|
||||||
gr.Examples(
|
example_table = gr.Examples(
|
||||||
|
examples=example_cases[:-2],
|
||||||
|
examples_per_page=20,
|
||||||
|
inputs=[prompt_audio,
|
||||||
|
emo_control_method,
|
||||||
|
input_text_single,
|
||||||
|
emo_upload,
|
||||||
|
emo_weight,
|
||||||
|
emo_text,
|
||||||
|
vec1,vec2,vec3,vec4,vec5,vec6,vec7,vec8,experimental_checkbox]
|
||||||
|
)
|
||||||
|
elif len(example_cases) > 0:
|
||||||
|
example_table = gr.Examples(
|
||||||
examples=example_cases,
|
examples=example_cases,
|
||||||
examples_per_page=20,
|
examples_per_page=20,
|
||||||
inputs=[prompt_audio,
|
inputs=[prompt_audio,
|
||||||
@@ -267,7 +295,7 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
|
|||||||
emo_upload,
|
emo_upload,
|
||||||
emo_weight,
|
emo_weight,
|
||||||
emo_text,
|
emo_text,
|
||||||
vec1,vec2,vec3,vec4,vec5,vec6,vec7,vec8]
|
vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, experimental_checkbox]
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_input_text_change(text, max_text_tokens_per_segment):
|
def on_input_text_change(text, max_text_tokens_per_segment):
|
||||||
@@ -288,6 +316,7 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
|
|||||||
return {
|
return {
|
||||||
segments_preview: gr.update(value=df),
|
segments_preview: gr.update(value=df),
|
||||||
}
|
}
|
||||||
|
|
||||||
def on_method_select(emo_control_method):
|
def on_method_select(emo_control_method):
|
||||||
if emo_control_method == 1: # emotion reference audio
|
if emo_control_method == 1: # emotion reference audio
|
||||||
return (gr.update(visible=True),
|
return (gr.update(visible=True),
|
||||||
@@ -301,7 +330,7 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
|
|||||||
gr.update(visible=True),
|
gr.update(visible=True),
|
||||||
gr.update(visible=True),
|
gr.update(visible=True),
|
||||||
gr.update(visible=False),
|
gr.update(visible=False),
|
||||||
gr.update(visible=True)
|
gr.update(visible=False)
|
||||||
)
|
)
|
||||||
elif emo_control_method == 3: # emotion text description
|
elif emo_control_method == 3: # emotion text description
|
||||||
return (gr.update(visible=False),
|
return (gr.update(visible=False),
|
||||||
@@ -318,6 +347,14 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
|
|||||||
gr.update(visible=False)
|
gr.update(visible=False)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def on_experimental_change(is_exp):
|
||||||
|
# 切换情感控制选项
|
||||||
|
# 第三个返回值实际没有起作用
|
||||||
|
if is_exp:
|
||||||
|
return gr.update(choices=EMO_CHOICES_EXPERIMENTAL, value=EMO_CHOICES_EXPERIMENTAL[0]), gr.update(visible=True),gr.update(value=example_cases)
|
||||||
|
else:
|
||||||
|
return gr.update(choices=EMO_CHOICES_BASE, value=EMO_CHOICES_BASE[0]), gr.update(visible=False),gr.update(value=example_cases[:-2])
|
||||||
|
|
||||||
emo_control_method.select(on_method_select,
|
emo_control_method.select(on_method_select,
|
||||||
inputs=[emo_control_method],
|
inputs=[emo_control_method],
|
||||||
outputs=[emotion_reference_group,
|
outputs=[emotion_reference_group,
|
||||||
@@ -332,11 +369,19 @@ with gr.Blocks(title="IndexTTS Demo") as demo:
|
|||||||
inputs=[input_text_single, max_text_tokens_per_segment],
|
inputs=[input_text_single, max_text_tokens_per_segment],
|
||||||
outputs=[segments_preview]
|
outputs=[segments_preview]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
experimental_checkbox.change(
|
||||||
|
on_experimental_change,
|
||||||
|
inputs=[experimental_checkbox],
|
||||||
|
outputs=[emo_control_method, advanced_settings_group,example_table.dataset] # 高级参数Accordion
|
||||||
|
)
|
||||||
|
|
||||||
max_text_tokens_per_segment.change(
|
max_text_tokens_per_segment.change(
|
||||||
on_input_text_change,
|
on_input_text_change,
|
||||||
inputs=[input_text_single, max_text_tokens_per_segment],
|
inputs=[input_text_single, max_text_tokens_per_segment],
|
||||||
outputs=[segments_preview]
|
outputs=[segments_preview]
|
||||||
)
|
)
|
||||||
|
|
||||||
prompt_audio.upload(update_prompt_audio,
|
prompt_audio.upload(update_prompt_audio,
|
||||||
inputs=[],
|
inputs=[],
|
||||||
outputs=[gen_button])
|
outputs=[gen_button])
|
||||||
|
|||||||
Reference in New Issue
Block a user