Add pitch merge (split voice to voice and pitch)

This commit is contained in:
litagin02
2024-02-03 00:11:08 +09:00
parent ea92d156a2
commit f9702ceb72

View File

@@ -14,7 +14,8 @@ from common.constants import DEFAULT_STYLE
from common.log import logger from common.log import logger
from common.tts_model import Model, ModelHolder from common.tts_model import Model, ModelHolder
voice_keys = ["dec", "flow"] voice_keys = ["dec"]
voice_pitch_keys = ["flow"]
speech_style_keys = ["enc_p"] speech_style_keys = ["enc_p"]
tempo_keys = ["sdp", "dp"] tempo_keys = ["sdp", "dp"]
@@ -93,6 +94,7 @@ def merge_models(
model_path_a, model_path_a,
model_path_b, model_path_b,
voice_weight, voice_weight,
voice_pitch_weight,
speech_style_weight, speech_style_weight,
tempo_weight, tempo_weight,
output_name, output_name,
@@ -114,6 +116,8 @@ def merge_models(
for key in model_a_weight.keys(): for key in model_a_weight.keys():
if any([key.startswith(prefix) for prefix in voice_keys]): if any([key.startswith(prefix) for prefix in voice_keys]):
weight = voice_weight weight = voice_weight
elif any([key.startswith(prefix) for prefix in voice_pitch_keys]):
weight = voice_pitch_weight
elif any([key.startswith(prefix) for prefix in speech_style_keys]): elif any([key.startswith(prefix) for prefix in speech_style_keys]):
weight = speech_style_weight weight = speech_style_weight
elif any([key.startswith(prefix) for prefix in tempo_keys]): elif any([key.startswith(prefix) for prefix in tempo_keys]):
@@ -139,6 +143,7 @@ def merge_models_gr(
model_path_b, model_path_b,
output_name, output_name,
voice_weight, voice_weight,
voice_pitch_weight,
speech_style_weight, speech_style_weight,
tempo_weight, tempo_weight,
): ):
@@ -146,6 +151,7 @@ def merge_models_gr(
model_path_a, model_path_a,
model_path_b, model_path_b,
voice_weight, voice_weight,
voice_pitch_weight,
speech_style_weight, speech_style_weight,
tempo_weight, tempo_weight,
output_name, output_name,
@@ -167,7 +173,10 @@ def merge_style_gr(
style_triple = line.split(",") style_triple = line.split(",")
if len(style_triple) != 3: if len(style_triple) != 3:
logger.error(f"Invalid style triple: {line}") logger.error(f"Invalid style triple: {line}")
return f"Error: スタイルを3つのカンマ区切りで入力してください:\n{line}", None return (
f"Error: スタイルを3つのカンマ区切りで入力してください:\n{line}",
None,
)
style_a, style_b, style_out = style_triple style_a, style_b, style_out = style_triple
style_a = style_a.strip() style_a = style_a.strip()
style_b = style_b.strip() style_b = style_b.strip()
@@ -184,13 +193,13 @@ def merge_style_gr(
) )
def simple_tts(model_name, text, style=DEFAULT_STYLE, emotion_weight=1.0): def simple_tts(model_name, text, style=DEFAULT_STYLE, style_weight=1.0):
model_path = os.path.join(assets_root, model_name, f"{model_name}.safetensors") model_path = os.path.join(assets_root, model_name, f"{model_name}.safetensors")
config_path = os.path.join(assets_root, model_name, "config.json") config_path = os.path.join(assets_root, model_name, "config.json")
style_vec_path = os.path.join(assets_root, model_name, "style_vectors.npy") style_vec_path = os.path.join(assets_root, model_name, "style_vectors.npy")
model = Model(model_path, config_path, style_vec_path, device) model = Model(model_path, config_path, style_vec_path, device)
return model.infer(text, style=style, style_weight=emotion_weight) return model.infer(text, style=style, style_weight=style_weight)
def update_two_model_names_dropdown(): def update_two_model_names_dropdown():
@@ -250,7 +259,9 @@ Happy, Surprise, HappySurprise
model_names = model_holder.model_names model_names = model_holder.model_names
if len(model_names) == 0: if len(model_names) == 0:
logger.error(f"モデルが見つかりませんでした。{assets_root}にモデルを置いてください。") logger.error(
f"モデルが見つかりませんでした。{assets_root}にモデルを置いてください。"
)
sys.exit(1) sys.exit(1)
initial_id = 0 initial_id = 0
initial_model_files = model_holder.model_files_dict[model_names[initial_id]] initial_model_files = model_holder.model_files_dict[model_names[initial_id]]
@@ -293,6 +304,13 @@ with gr.Blocks(theme="NoCrypt/miku") as app:
maximum=1, maximum=1,
step=0.1, step=0.1,
) )
voice_pitch_slider = gr.Slider(
label="声の高さ",
value=0,
minimum=0,
maximum=1,
step=0.1,
)
speech_style_slider = gr.Slider( speech_style_slider = gr.Slider(
label="話し方(抑揚・感情表現等)", label="話し方(抑揚・感情表現等)",
value=0, value=0,
@@ -325,7 +343,9 @@ with gr.Blocks(theme="NoCrypt/miku") as app:
style_merge_button = gr.Button("スタイルのマージ", variant="primary") style_merge_button = gr.Button("スタイルのマージ", variant="primary")
info_style_merge = gr.Textbox(label="情報") info_style_merge = gr.Textbox(label="情報")
text_input = gr.TextArea(label="テキスト", value="これはテストです。聞こえていますか?") text_input = gr.TextArea(
label="テキスト", value="これはテストです。聞こえていますか?"
)
style = gr.Dropdown( style = gr.Dropdown(
label="スタイル", label="スタイル",
choices=["スタイルをマージしてください"], choices=["スタイルをマージしてください"],
@@ -372,6 +392,7 @@ with gr.Blocks(theme="NoCrypt/miku") as app:
model_path_b, model_path_b,
new_name, new_name,
voice_slider, voice_slider,
voice_pitch_slider,
speech_style_slider, speech_style_slider,
tempo_slider, tempo_slider,
], ],