Refactor: minor adjustments
This commit is contained in:
@@ -7,7 +7,7 @@ from style_bert_vits2.constants import Languages
|
|||||||
from style_bert_vits2.text_processing import bert_models
|
from style_bert_vits2.text_processing import bert_models
|
||||||
|
|
||||||
|
|
||||||
models: dict[str, PreTrainedModel] = {}
|
models: dict[torch.device | str, PreTrainedModel] = {}
|
||||||
|
|
||||||
|
|
||||||
def extract_bert_feature(
|
def extract_bert_feature(
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from style_bert_vits2.constants import Languages
|
|||||||
from style_bert_vits2.text_processing import bert_models
|
from style_bert_vits2.text_processing import bert_models
|
||||||
|
|
||||||
|
|
||||||
models: dict[str, PreTrainedModel] = {}
|
models: dict[torch.device | str, PreTrainedModel] = {}
|
||||||
|
|
||||||
|
|
||||||
def extract_bert_feature(
|
def extract_bert_feature(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from style_bert_vits2.text_processing import bert_models
|
|||||||
from style_bert_vits2.text_processing.japanese.g2p import text_to_sep_kata
|
from style_bert_vits2.text_processing.japanese.g2p import text_to_sep_kata
|
||||||
|
|
||||||
|
|
||||||
models: dict[str, PreTrainedModel] = {}
|
models: dict[torch.device | str, PreTrainedModel] = {}
|
||||||
|
|
||||||
|
|
||||||
def extract_bert_feature(
|
def extract_bert_feature(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from style_bert_vits2.text_processing.symbols import PUNCTUATIONS
|
|||||||
def g2kata_tone(norm_text: str) -> list[tuple[str, int]]:
|
def g2kata_tone(norm_text: str) -> list[tuple[str, int]]:
|
||||||
"""
|
"""
|
||||||
テキストからカタカナとアクセントのペアのリストを返す。
|
テキストからカタカナとアクセントのペアのリストを返す。
|
||||||
推論時のみに使われるので、常に `raise_yomi_error=False` で g2p を呼ぶ。
|
推論時のみに使われる関数のため、常に `raise_yomi_error=False` を指定して g2p() を呼ぶ仕様になっている。
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
norm_text: 正規化されたテキスト。
|
norm_text: 正規化されたテキスト。
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ ZH_SYMBOLS = [
|
|||||||
]
|
]
|
||||||
NUM_ZH_TONES = 6
|
NUM_ZH_TONES = 6
|
||||||
|
|
||||||
# japanese
|
# Japanese
|
||||||
JA_SYMBOLS = [
|
JP_SYMBOLS = [
|
||||||
"N",
|
"N",
|
||||||
"a",
|
"a",
|
||||||
"a:",
|
"a:",
|
||||||
@@ -122,7 +122,7 @@ JA_SYMBOLS = [
|
|||||||
"z",
|
"z",
|
||||||
"zy",
|
"zy",
|
||||||
]
|
]
|
||||||
NUM_JA_TONES = 2
|
NUM_JP_TONES = 2
|
||||||
|
|
||||||
# English
|
# English
|
||||||
EN_SYMBOLS = [
|
EN_SYMBOLS = [
|
||||||
@@ -169,23 +169,25 @@ EN_SYMBOLS = [
|
|||||||
NUM_EN_TONES = 4
|
NUM_EN_TONES = 4
|
||||||
|
|
||||||
# Combine all symbols
|
# Combine all symbols
|
||||||
NORMAL_SYMBOLS = sorted(set(ZH_SYMBOLS + JA_SYMBOLS + EN_SYMBOLS))
|
NORMAL_SYMBOLS = sorted(set(ZH_SYMBOLS + JP_SYMBOLS + EN_SYMBOLS))
|
||||||
SYMBOLS = [PAD] + NORMAL_SYMBOLS + PUNCTUATION_SYMBOLS
|
SYMBOLS = [PAD] + NORMAL_SYMBOLS + PUNCTUATION_SYMBOLS
|
||||||
SIL_PHONEMES_IDS = [SYMBOLS.index(i) for i in PUNCTUATION_SYMBOLS]
|
SIL_PHONEMES_IDS = [SYMBOLS.index(i) for i in PUNCTUATION_SYMBOLS]
|
||||||
|
|
||||||
# Combine all tones
|
# Combine all tones
|
||||||
NUM_TONES = NUM_ZH_TONES + NUM_JA_TONES + NUM_EN_TONES
|
NUM_TONES = NUM_ZH_TONES + NUM_JP_TONES + NUM_EN_TONES
|
||||||
|
|
||||||
# Language maps
|
# Language maps
|
||||||
LANGUAGE_ID_MAP = {"ZH": 0, "JP": 1, "EN": 2}
|
LANGUAGE_ID_MAP = {"ZH": 0, "JP": 1, "EN": 2}
|
||||||
NUM_LANGUAGES = len(LANGUAGE_ID_MAP.keys())
|
NUM_LANGUAGES = len(LANGUAGE_ID_MAP.keys())
|
||||||
|
|
||||||
|
# Language tone start map
|
||||||
LANGUAGE_TONE_START_MAP = {
|
LANGUAGE_TONE_START_MAP = {
|
||||||
"ZH": 0,
|
"ZH": 0,
|
||||||
"JP": NUM_ZH_TONES,
|
"JP": NUM_ZH_TONES,
|
||||||
"EN": NUM_ZH_TONES + NUM_JA_TONES,
|
"EN": NUM_ZH_TONES + NUM_JP_TONES,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
a = set(ZH_SYMBOLS)
|
a = set(ZH_SYMBOLS)
|
||||||
b = set(EN_SYMBOLS)
|
b = set(EN_SYMBOLS)
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ from typing import Any, Callable
|
|||||||
from style_bert_vits2.logging import logger
|
from style_bert_vits2.logging import logger
|
||||||
from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT
|
from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT
|
||||||
|
|
||||||
PYTHON = sys.executable
|
|
||||||
|
|
||||||
|
|
||||||
def run_script_with_log(cmd: list[str], ignore_warning: bool = False) -> tuple[bool, str]:
|
def run_script_with_log(cmd: list[str], ignore_warning: bool = False) -> tuple[bool, str]:
|
||||||
"""
|
"""
|
||||||
@@ -22,7 +20,7 @@ def run_script_with_log(cmd: list[str], ignore_warning: bool = False) -> tuple[b
|
|||||||
|
|
||||||
logger.info(f"Running: {' '.join(cmd)}")
|
logger.info(f"Running: {' '.join(cmd)}")
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
[PYTHON] + cmd,
|
[sys.executable] + cmd,
|
||||||
stdout = SAFE_STDOUT,
|
stdout = SAFE_STDOUT,
|
||||||
stderr = subprocess.PIPE,
|
stderr = subprocess.PIPE,
|
||||||
text = True,
|
text = True,
|
||||||
|
|||||||
15
utils.py
15
utils.py
@@ -450,21 +450,6 @@ class HParams:
|
|||||||
return self.__dict__.__repr__()
|
return self.__dict__.__repr__()
|
||||||
|
|
||||||
|
|
||||||
def load_model(model_path, config_path):
|
|
||||||
hps = get_hparams_from_file(config_path)
|
|
||||||
net = SynthesizerTrn(
|
|
||||||
# len(symbols),
|
|
||||||
108,
|
|
||||||
hps.data.filter_length // 2 + 1,
|
|
||||||
hps.train.segment_size // hps.data.hop_length,
|
|
||||||
n_speakers=hps.data.n_speakers,
|
|
||||||
**hps.model,
|
|
||||||
).to("cpu")
|
|
||||||
_ = net.eval()
|
|
||||||
_ = load_checkpoint(model_path, net, None, skip_optimizer=True)
|
|
||||||
return net
|
|
||||||
|
|
||||||
|
|
||||||
def mix_model(
|
def mix_model(
|
||||||
network1, network2, output_path, voice_ratio=(0.5, 0.5), tone_ratio=(0.5, 0.5)
|
network1, network2, output_path, voice_ratio=(0.5, 0.5), tone_ratio=(0.5, 0.5)
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user