Refactor: minor adjustments

This commit is contained in:
tsukumi
2024-03-07 03:54:02 +00:00
parent 62919e904e
commit 4f11b011fd
8 changed files with 18 additions and 33 deletions

View File

@@ -7,7 +7,7 @@ from style_bert_vits2.constants import Languages
from style_bert_vits2.text_processing import bert_models
models: dict[str, PreTrainedModel] = {}
models: dict[torch.device | str, PreTrainedModel] = {}
def extract_bert_feature(

View File

@@ -7,7 +7,7 @@ from style_bert_vits2.constants import Languages
from style_bert_vits2.text_processing import bert_models
models: dict[str, PreTrainedModel] = {}
models: dict[torch.device | str, PreTrainedModel] = {}
def extract_bert_feature(

View File

@@ -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
models: dict[str, PreTrainedModel] = {}
models: dict[torch.device | str, PreTrainedModel] = {}
def extract_bert_feature(

View File

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

View File

@@ -9,7 +9,7 @@ from style_bert_vits2.text_processing.symbols import PUNCTUATIONS
def g2kata_tone(norm_text: str) -> list[tuple[str, int]]:
"""
テキストからカタカナとアクセントのペアのリストを返す。
推論時のみに使われるので、常に `raise_yomi_error=False` g2p を呼ぶ。
推論時のみに使われる関数のため、常に `raise_yomi_error=False` を指定して g2p() を呼ぶ仕様になっている
Args:
norm_text: 正規化されたテキスト。

View File

@@ -77,8 +77,8 @@ ZH_SYMBOLS = [
]
NUM_ZH_TONES = 6
# japanese
JA_SYMBOLS = [
# Japanese
JP_SYMBOLS = [
"N",
"a",
"a:",
@@ -122,7 +122,7 @@ JA_SYMBOLS = [
"z",
"zy",
]
NUM_JA_TONES = 2
NUM_JP_TONES = 2
# English
EN_SYMBOLS = [
@@ -169,23 +169,25 @@ EN_SYMBOLS = [
NUM_EN_TONES = 4
# 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
SIL_PHONEMES_IDS = [SYMBOLS.index(i) for i in PUNCTUATION_SYMBOLS]
# 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_ID_MAP = {"ZH": 0, "JP": 1, "EN": 2}
NUM_LANGUAGES = len(LANGUAGE_ID_MAP.keys())
# Language tone start map
LANGUAGE_TONE_START_MAP = {
"ZH": 0,
"JP": NUM_ZH_TONES,
"EN": NUM_ZH_TONES + NUM_JA_TONES,
"EN": NUM_ZH_TONES + NUM_JP_TONES,
}
if __name__ == "__main__":
a = set(ZH_SYMBOLS)
b = set(EN_SYMBOLS)

View File

@@ -5,8 +5,6 @@ from typing import Any, Callable
from style_bert_vits2.logging import logger
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]:
"""
@@ -22,7 +20,7 @@ def run_script_with_log(cmd: list[str], ignore_warning: bool = False) -> tuple[b
logger.info(f"Running: {' '.join(cmd)}")
result = subprocess.run(
[PYTHON] + cmd,
[sys.executable] + cmd,
stdout = SAFE_STDOUT,
stderr = subprocess.PIPE,
text = True,