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(
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ def __kata_to_phoneme_list(text: str) -> list[str]:
|
|||||||
|
|
||||||
if set(text).issubset(set(PUNCTUATIONS)):
|
if set(text).issubset(set(PUNCTUATIONS)):
|
||||||
return list(text)
|
return list(text)
|
||||||
# `text`がカタカナ(`ー`含む)のみからなるかどうかをチェック
|
# `text` がカタカナ(`ー`含む)のみからなるかどうかをチェック
|
||||||
if re.fullmatch(r"[\u30A0-\u30FF]+", text) is None:
|
if re.fullmatch(r"[\u30A0-\u30FF]+", text) is None:
|
||||||
raise ValueError(f"Input must be katakana only: {text}")
|
raise ValueError(f"Input must be katakana only: {text}")
|
||||||
sorted_keys = sorted(MORA_KATA_TO_MORA_PHONEMES.keys(), key=len, reverse=True)
|
sorted_keys = sorted(MORA_KATA_TO_MORA_PHONEMES.keys(), key=len, reverse=True)
|
||||||
@@ -438,15 +438,15 @@ def __align_tones(
|
|||||||
tone_index = 0
|
tone_index = 0
|
||||||
for phone in phones_with_punct:
|
for phone in phones_with_punct:
|
||||||
if tone_index >= len(phone_tone_list):
|
if tone_index >= len(phone_tone_list):
|
||||||
# 余ったpunctuationがある場合 → (punctuation, 0)を追加
|
# 余った punctuation がある場合 → (punctuation, 0) を追加
|
||||||
result.append((phone, 0))
|
result.append((phone, 0))
|
||||||
elif phone == phone_tone_list[tone_index][0]:
|
elif phone == phone_tone_list[tone_index][0]:
|
||||||
# phone_tone_listの現在の音素と一致する場合 → toneをそこから取得、(phone, tone)を追加
|
# phone_tone_list の現在の音素と一致する場合 → tone をそこから取得、(phone, tone) を追加
|
||||||
result.append((phone, phone_tone_list[tone_index][1]))
|
result.append((phone, phone_tone_list[tone_index][1]))
|
||||||
# 探すindexを1つ進める
|
# 探す index を1つ進める
|
||||||
tone_index += 1
|
tone_index += 1
|
||||||
elif phone in PUNCTUATIONS:
|
elif phone in PUNCTUATIONS:
|
||||||
# phoneがpunctuationの場合 → (phone, 0)を追加
|
# phone が punctuation の場合 → (phone, 0) を追加
|
||||||
result.append((phone, 0))
|
result.append((phone, 0))
|
||||||
else:
|
else:
|
||||||
logger.debug(f"phones: {phones_with_punct}")
|
logger.debug(f"phones: {phones_with_punct}")
|
||||||
|
|||||||
@@ -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