From 1936344c0c6af8213b4327cb964b32dbd20130ba Mon Sep 17 00:00:00 2001 From: tsukumi Date: Wed, 6 Mar 2024 22:51:25 +0000 Subject: [PATCH] Refactor: remove old code that can be deleted and update where modules are imported --- app.py | 5 +- infer.py | 6 +- models.py | 8 +- models_jp_extra.py | 8 +- style_bert_vits2/text_processing/symbols.py | 2 +- text/__init__.py | 8 +- text/chinese.py | 8 +- text/english.py | 13 +- text/japanese.py | 34 ++- text/japanese_bert.py | 6 +- text/japanese_mora_list.py | 232 -------------------- text/symbols.py | 187 ---------------- train_ms.py | 4 +- train_ms_jp_extra.py | 4 +- 14 files changed, 52 insertions(+), 473 deletions(-) delete mode 100644 text/japanese_mora_list.py delete mode 100644 text/symbols.py diff --git a/app.py b/app.py index acdb646..c70a89d 100644 --- a/app.py +++ b/app.py @@ -27,7 +27,8 @@ from style_bert_vits2.constants import ( from style_bert_vits2.logging import logger from common.tts_model import ModelHolder from infer import InvalidToneError -from text.japanese import g2kata_tone, kata_tone2phone_tone, text_normalize +from style_bert_vits2.text_processing.japanese.g2p_utils import g2kata_tone, kata_tone2phone_tone +from style_bert_vits2.text_processing.japanese.normalizer import normalize_text # Get path settings with open(os.path.join("configs", "paths.yml"), "r", encoding="utf-8") as f: @@ -131,7 +132,7 @@ def tts_fn( if tone is None and language == "JP": # アクセント指定に使えるようにアクセント情報を返す - norm_text = text_normalize(text) + norm_text = normalize_text(text) kata_tone = g2kata_tone(norm_text) kata_tone_json_str = json.dumps(kata_tone, ensure_ascii=False) elif tone is None: diff --git a/infer.py b/infer.py index 525219d..4afd048 100644 --- a/infer.py +++ b/infer.py @@ -6,7 +6,7 @@ from models import SynthesizerTrn from models_jp_extra import SynthesizerTrn as SynthesizerTrnJPExtra from text import cleaned_text_to_sequence, get_bert from text.cleaner import clean_text -from text.symbols import symbols +from style_bert_vits2.text_processing.symbols import SYMBOLS from style_bert_vits2.logging import logger @@ -18,7 +18,7 @@ def get_net_g(model_path: str, version: str, device: str, hps): if version.endswith("JP-Extra"): logger.info("Using JP-Extra model") net_g = SynthesizerTrnJPExtra( - len(symbols), + len(SYMBOLS), hps.data.filter_length // 2 + 1, hps.train.segment_size // hps.data.hop_length, n_speakers=hps.data.n_speakers, @@ -27,7 +27,7 @@ def get_net_g(model_path: str, version: str, device: str, hps): else: logger.info("Using normal model") net_g = SynthesizerTrn( - len(symbols), + len(SYMBOLS), hps.data.filter_length // 2 + 1, hps.train.segment_size // hps.data.hop_length, n_speakers=hps.data.n_speakers, diff --git a/models.py b/models.py index 501fcaf..ef581f2 100644 --- a/models.py +++ b/models.py @@ -12,7 +12,7 @@ from style_bert_vits2.models import commons import modules import monotonic_align from style_bert_vits2.models.commons import get_padding, init_weights -from text import num_languages, num_tones, symbols +from style_bert_vits2.text_processing.symbols import NUM_LANGUAGES, NUM_TONES, SYMBOLS class DurationDiscriminator(nn.Module): # vits2 @@ -334,11 +334,11 @@ class TextEncoder(nn.Module): self.kernel_size = kernel_size self.p_dropout = p_dropout self.gin_channels = gin_channels - self.emb = nn.Embedding(len(symbols), hidden_channels) + self.emb = nn.Embedding(len(SYMBOLS), hidden_channels) nn.init.normal_(self.emb.weight, 0.0, hidden_channels**-0.5) - self.tone_emb = nn.Embedding(num_tones, hidden_channels) + self.tone_emb = nn.Embedding(NUM_TONES, hidden_channels) nn.init.normal_(self.tone_emb.weight, 0.0, hidden_channels**-0.5) - self.language_emb = nn.Embedding(num_languages, hidden_channels) + self.language_emb = nn.Embedding(NUM_LANGUAGES, hidden_channels) nn.init.normal_(self.language_emb.weight, 0.0, hidden_channels**-0.5) self.bert_proj = nn.Conv1d(1024, hidden_channels, 1) self.ja_bert_proj = nn.Conv1d(1024, hidden_channels, 1) diff --git a/models_jp_extra.py b/models_jp_extra.py index 3e87ced..16cacc7 100644 --- a/models_jp_extra.py +++ b/models_jp_extra.py @@ -12,7 +12,7 @@ from torch.nn import Conv1d, ConvTranspose1d, Conv2d from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm from style_bert_vits2.models.commons import init_weights, get_padding -from text import symbols, num_tones, num_languages +from style_bert_vits2.text_processing.symbols import SYMBOLS, NUM_TONES, NUM_LANGUAGES class DurationDiscriminator(nn.Module): # vits2 @@ -353,11 +353,11 @@ class TextEncoder(nn.Module): self.kernel_size = kernel_size self.p_dropout = p_dropout self.gin_channels = gin_channels - self.emb = nn.Embedding(len(symbols), hidden_channels) + self.emb = nn.Embedding(len(SYMBOLS), hidden_channels) nn.init.normal_(self.emb.weight, 0.0, hidden_channels**-0.5) - self.tone_emb = nn.Embedding(num_tones, hidden_channels) + self.tone_emb = nn.Embedding(NUM_TONES, hidden_channels) nn.init.normal_(self.tone_emb.weight, 0.0, hidden_channels**-0.5) - self.language_emb = nn.Embedding(num_languages, hidden_channels) + self.language_emb = nn.Embedding(NUM_LANGUAGES, hidden_channels) nn.init.normal_(self.language_emb.weight, 0.0, hidden_channels**-0.5) self.bert_proj = nn.Conv1d(1024, hidden_channels, 1) diff --git a/style_bert_vits2/text_processing/symbols.py b/style_bert_vits2/text_processing/symbols.py index 628edc6..d69bc1c 100644 --- a/style_bert_vits2/text_processing/symbols.py +++ b/style_bert_vits2/text_processing/symbols.py @@ -174,7 +174,7 @@ 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_JA_TONES + NUM_EN_TONES # Language maps LANGUAGE_ID_MAP = {"ZH": 0, "JP": 1, "EN": 2} diff --git a/text/__init__.py b/text/__init__.py index d8ae88d..ce4c008 100644 --- a/text/__init__.py +++ b/text/__init__.py @@ -1,6 +1,6 @@ -from text.symbols import * +from style_bert_vits2.text_processing.symbols import * -_symbol_to_id = {s: i for i, s in enumerate(symbols)} +_symbol_to_id = {s: i for i, s in enumerate(SYMBOLS)} def cleaned_text_to_sequence(cleaned_text, tones, language): @@ -11,9 +11,9 @@ def cleaned_text_to_sequence(cleaned_text, tones, language): List of integers corresponding to the symbols in the text """ phones = [_symbol_to_id[symbol] for symbol in cleaned_text] - tone_start = language_tone_start_map[language] + tone_start = LANGUAGE_TONE_START_MAP[language] tones = [i + tone_start for i in tones] - lang_id = language_id_map[language] + lang_id = LANGUAGE_ID_MAP[language] lang_ids = [lang_id for i in phones] return phones, tones, lang_ids diff --git a/text/chinese.py b/text/chinese.py index d9174ee..56dc4f3 100644 --- a/text/chinese.py +++ b/text/chinese.py @@ -4,7 +4,7 @@ import re import cn2an from pypinyin import lazy_pinyin, Style -from text.symbols import punctuation +from style_bert_vits2.text_processing.symbols import PUNCTUATIONS from text.tone_sandhi import ToneSandhi current_file_path = os.path.dirname(__file__) @@ -60,14 +60,14 @@ def replace_punctuation(text): replaced_text = pattern.sub(lambda x: rep_map[x.group()], text) replaced_text = re.sub( - r"[^\u4e00-\u9fa5" + "".join(punctuation) + r"]+", "", replaced_text + r"[^\u4e00-\u9fa5" + "".join(PUNCTUATIONS) + r"]+", "", replaced_text ) return replaced_text def g2p(text): - pattern = r"(?<=[{0}])\s*".format("".join(punctuation)) + pattern = r"(?<=[{0}])\s*".format("".join(PUNCTUATIONS)) sentences = [i for i in re.split(pattern, text) if i.strip() != ""] phones, tones, word2ph = _g2p(sentences) assert sum(word2ph) == len(phones) @@ -119,7 +119,7 @@ def _g2p(segments): # NOTE: post process for pypinyin outputs # we discriminate i, ii and iii if c == v: - assert c in punctuation + assert c in PUNCTUATIONS phone = [c] tone = "0" word2ph.append(1) diff --git a/text/english.py b/text/english.py index 4a2af95..f38ee84 100644 --- a/text/english.py +++ b/text/english.py @@ -4,8 +4,7 @@ import re from g2p_en import G2p from transformers import DebertaV2Tokenizer -from text import symbols -from text.symbols import punctuation +from style_bert_vits2.text_processing.symbols import PUNCTUATIONS, SYMBOLS current_file_path = os.path.dirname(__file__) CMU_DICT_PATH = os.path.join(current_file_path, "cmudict.rep") @@ -107,9 +106,9 @@ def post_replace_ph(ph): } if ph in rep_map.keys(): ph = rep_map[ph] - if ph in symbols: + if ph in SYMBOLS: return ph - if ph not in symbols: + if ph not in SYMBOLS: ph = "UNK" return ph @@ -399,13 +398,13 @@ def text_to_words(text): if t.startswith("▁"): words.append([t[1:]]) else: - if t in punctuation: + if t in PUNCTUATIONS: if idx == len(tokens) - 1: words.append([f"{t}"]) else: if ( not tokens[idx + 1].startswith("▁") - and tokens[idx + 1] not in punctuation + and tokens[idx + 1] not in PUNCTUATIONS ): if idx == 0: words.append([]) @@ -433,7 +432,7 @@ def g2p(text): if "'" in word: word = ["".join(word)] for w in word: - if w in punctuation: + if w in PUNCTUATIONS: temp_phones.append(w) temp_tones.append(0) continue diff --git a/text/japanese.py b/text/japanese.py index 12dc349..0dc6aa8 100644 --- a/text/japanese.py +++ b/text/japanese.py @@ -2,20 +2,18 @@ # compatible with Julius https://github.com/julius-speech/segmentation-kit import re import unicodedata -from pathlib import Path import pyopenjtalk from num2words import num2words from transformers import AutoTokenizer from style_bert_vits2.logging import logger -from text import punctuation -from text.japanese_mora_list import ( - mora_kata_to_mora_phonemes, - mora_phonemes_to_mora_kata, +from style_bert_vits2.text_processing.japanese.mora_list import ( + MORA_KATA_TO_MORA_PHONEMES, + MORA_PHONEMES_TO_MORA_KATA, ) - from style_bert_vits2.text_processing.japanese.user_dict import update_dict +from style_bert_vits2.text_processing.symbols import PUNCTUATIONS # 最初にpyopenjtalkの辞書を更新 update_dict() @@ -24,7 +22,7 @@ update_dict() COSONANTS = set( [ cosonant - for cosonant, _ in mora_kata_to_mora_phonemes.values() + for cosonant, _ in MORA_KATA_TO_MORA_PHONEMES.values() if cosonant is not None ] ) @@ -153,7 +151,7 @@ def replace_punctuation(text: str) -> str: # ↓ ギリシャ文字 + r"\u0370-\u03FF\u1F00-\u1FFF" # ↓ "!", "?", "…", ",", ".", "'", "-", 但し`…`はすでに`...`に変換されている - + "".join(punctuation) + r"]+", + + "".join(PUNCTUATIONS) + r"]+", # 上述以外の文字を削除 "", replaced_text, @@ -220,7 +218,7 @@ def g2p( # sep_textから、各単語を1文字1文字分割して、文字のリスト(のリスト)を作る sep_tokenized: list[list[str]] = [] for i in sep_text: - if i not in punctuation: + if i not in PUNCTUATIONS: sep_tokenized.append( tokenizer.tokenize(i) ) # ここでおそらく`i`が文字単位に分割される @@ -268,7 +266,7 @@ def phone_tone2kata_tone(phone_tone: list[tuple[str, int]]) -> list[tuple[str, i current_mora = "" for phone, next_phone, tone, next_tone in zip(phones, phones[1:], tones, tones[1:]): # zipの関係で最後の("_", 0)は無視されている - if phone in punctuation: + if phone in PUNCTUATIONS: result.append((phone, tone)) continue if phone in COSONANTS: # n以外の子音の場合 @@ -278,7 +276,7 @@ def phone_tone2kata_tone(phone_tone: list[tuple[str, int]]) -> list[tuple[str, i else: # phoneが母音もしくは「N」 current_mora += phone - result.append((mora_phonemes_to_mora_kata[current_mora], tone)) + result.append((MORA_PHONEMES_TO_MORA_KATA[current_mora], tone)) current_mora = "" return result @@ -287,10 +285,10 @@ def kata_tone2phone_tone(kata_tone: list[tuple[str, int]]) -> list[tuple[str, in """`phone_tone2kata_tone()`の逆。""" result: list[tuple[str, int]] = [("_", 0)] for mora, tone in kata_tone: - if mora in punctuation: + if mora in PUNCTUATIONS: result.append((mora, tone)) else: - cosonant, vowel = mora_kata_to_mora_phonemes[mora] + cosonant, vowel = MORA_KATA_TO_MORA_PHONEMES[mora] if cosonant is None: result.append((vowel, tone)) else: @@ -387,7 +385,7 @@ def text2sep_kata( assert yomi != "", f"Empty yomi: {word}" if yomi == "、": # wordは正規化されているので、`.`, `,`, `!`, `'`, `-`, `--` のいずれか - if not set(word).issubset(set(punctuation)): # 記号繰り返しか判定 + if not set(word).issubset(set(PUNCTUATIONS)): # 記号繰り返しか判定 # ここはpyopenjtalkが読めない文字等のときに起こる if raise_yomi_error: raise YomiError(f"Cannot read: {word} in:\n{norm_text}") @@ -581,7 +579,7 @@ def align_tones( result.append((phone, phone_tone_list[tone_index][1])) # 探すindexを1つ進める tone_index += 1 - elif phone in punctuation: + elif phone in PUNCTUATIONS: # phoneがpunctuationの場合 → (phone, 0)を追加 result.append((phone, 0)) else: @@ -606,16 +604,16 @@ def kata2phoneme_list(text: str) -> list[str]: `?` → ["?"] `!?!?!?!?!` → ["!", "?", "!", "?", "!", "?", "!", "?", "!"] """ - if set(text).issubset(set(punctuation)): + if set(text).issubset(set(PUNCTUATIONS)): return list(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) + sorted_keys = sorted(MORA_KATA_TO_MORA_PHONEMES.keys(), key=len, reverse=True) pattern = "|".join(map(re.escape, sorted_keys)) def mora2phonemes(mora: str) -> str: - cosonant, vowel = mora_kata_to_mora_phonemes[mora] + cosonant, vowel = MORA_KATA_TO_MORA_PHONEMES[mora] if cosonant is None: return f" {vowel}" return f" {cosonant} {vowel}" diff --git a/text/japanese_bert.py b/text/japanese_bert.py index dcee0f3..fbeb94d 100644 --- a/text/japanese_bert.py +++ b/text/japanese_bert.py @@ -4,7 +4,7 @@ import torch from transformers import AutoModelForMaskedLM, AutoTokenizer from config import config -from text.japanese import text2sep_kata, text_normalize +from style_bert_vits2.text_processing.japanese.g2p import text_to_sep_kata LOCAL_PATH = "./bert/deberta-v2-large-japanese-char-wwm" @@ -22,10 +22,10 @@ def get_bert_feature( ): # 各単語が何文字かを作る`word2ph`を使う必要があるので、読めない文字は必ず無視する # でないと`word2ph`の結果とテキストの文字数結果が整合性が取れない - text = "".join(text2sep_kata(text, raise_yomi_error=False)[0]) + text = "".join(text_to_sep_kata(text, raise_yomi_error=False)[0]) if assist_text: - assist_text = "".join(text2sep_kata(assist_text, raise_yomi_error=False)[0]) + assist_text = "".join(text_to_sep_kata(assist_text, raise_yomi_error=False)[0]) if ( sys.platform == "darwin" and torch.backends.mps.is_available() diff --git a/text/japanese_mora_list.py b/text/japanese_mora_list.py deleted file mode 100644 index b43e54d..0000000 --- a/text/japanese_mora_list.py +++ /dev/null @@ -1,232 +0,0 @@ -""" -VOICEVOXのソースコードからお借りして最低限に改造したコード。 -https://github.com/VOICEVOX/voicevox_engine/blob/master/voicevox_engine/tts_pipeline/mora_list.py -""" - -""" -以下のモーラ対応表はOpenJTalkのソースコードから取得し、 -カタカナ表記とモーラが一対一対応するように改造した。 -ライセンス表記: ------------------------------------------------------------------ - The Japanese TTS System "Open JTalk" - developed by HTS Working Group - http://open-jtalk.sourceforge.net/ ------------------------------------------------------------------ - - Copyright (c) 2008-2014 Nagoya Institute of Technology - Department of Computer Science - -All rights reserved. - -Redistribution and use in source and binary forms, with or -without modification, are permitted provided that the following -conditions are met: - -- Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -- Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. -- Neither the name of the HTS working group nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -""" -from typing import Optional - -# (カタカナ, 子音, 母音)の順。子音がない場合はNoneを入れる。 -# 但し「ン」と「ッ」は母音のみという扱いで、「ン」は「N」、「ッ」は「q」とする。 -# (元々「ッ」は「cl」) -# また「デェ = dy e」はpyopenjtalkの出力(de e)と合わないため削除 -_mora_list_minimum: list[tuple[str, Optional[str], str]] = [ - ("ヴォ", "v", "o"), - ("ヴェ", "v", "e"), - ("ヴィ", "v", "i"), - ("ヴァ", "v", "a"), - ("ヴ", "v", "u"), - ("ン", None, "N"), - ("ワ", "w", "a"), - ("ロ", "r", "o"), - ("レ", "r", "e"), - ("ル", "r", "u"), - ("リョ", "ry", "o"), - ("リュ", "ry", "u"), - ("リャ", "ry", "a"), - ("リェ", "ry", "e"), - ("リ", "r", "i"), - ("ラ", "r", "a"), - ("ヨ", "y", "o"), - ("ユ", "y", "u"), - ("ヤ", "y", "a"), - ("モ", "m", "o"), - ("メ", "m", "e"), - ("ム", "m", "u"), - ("ミョ", "my", "o"), - ("ミュ", "my", "u"), - ("ミャ", "my", "a"), - ("ミェ", "my", "e"), - ("ミ", "m", "i"), - ("マ", "m", "a"), - ("ポ", "p", "o"), - ("ボ", "b", "o"), - ("ホ", "h", "o"), - ("ペ", "p", "e"), - ("ベ", "b", "e"), - ("ヘ", "h", "e"), - ("プ", "p", "u"), - ("ブ", "b", "u"), - ("フォ", "f", "o"), - ("フェ", "f", "e"), - ("フィ", "f", "i"), - ("ファ", "f", "a"), - ("フ", "f", "u"), - ("ピョ", "py", "o"), - ("ピュ", "py", "u"), - ("ピャ", "py", "a"), - ("ピェ", "py", "e"), - ("ピ", "p", "i"), - ("ビョ", "by", "o"), - ("ビュ", "by", "u"), - ("ビャ", "by", "a"), - ("ビェ", "by", "e"), - ("ビ", "b", "i"), - ("ヒョ", "hy", "o"), - ("ヒュ", "hy", "u"), - ("ヒャ", "hy", "a"), - ("ヒェ", "hy", "e"), - ("ヒ", "h", "i"), - ("パ", "p", "a"), - ("バ", "b", "a"), - ("ハ", "h", "a"), - ("ノ", "n", "o"), - ("ネ", "n", "e"), - ("ヌ", "n", "u"), - ("ニョ", "ny", "o"), - ("ニュ", "ny", "u"), - ("ニャ", "ny", "a"), - ("ニェ", "ny", "e"), - ("ニ", "n", "i"), - ("ナ", "n", "a"), - ("ドゥ", "d", "u"), - ("ド", "d", "o"), - ("トゥ", "t", "u"), - ("ト", "t", "o"), - ("デョ", "dy", "o"), - ("デュ", "dy", "u"), - ("デャ", "dy", "a"), - # ("デェ", "dy", "e"), - ("ディ", "d", "i"), - ("デ", "d", "e"), - ("テョ", "ty", "o"), - ("テュ", "ty", "u"), - ("テャ", "ty", "a"), - ("ティ", "t", "i"), - ("テ", "t", "e"), - ("ツォ", "ts", "o"), - ("ツェ", "ts", "e"), - ("ツィ", "ts", "i"), - ("ツァ", "ts", "a"), - ("ツ", "ts", "u"), - ("ッ", None, "q"), # 「cl」から「q」に変更 - ("チョ", "ch", "o"), - ("チュ", "ch", "u"), - ("チャ", "ch", "a"), - ("チェ", "ch", "e"), - ("チ", "ch", "i"), - ("ダ", "d", "a"), - ("タ", "t", "a"), - ("ゾ", "z", "o"), - ("ソ", "s", "o"), - ("ゼ", "z", "e"), - ("セ", "s", "e"), - ("ズィ", "z", "i"), - ("ズ", "z", "u"), - ("スィ", "s", "i"), - ("ス", "s", "u"), - ("ジョ", "j", "o"), - ("ジュ", "j", "u"), - ("ジャ", "j", "a"), - ("ジェ", "j", "e"), - ("ジ", "j", "i"), - ("ショ", "sh", "o"), - ("シュ", "sh", "u"), - ("シャ", "sh", "a"), - ("シェ", "sh", "e"), - ("シ", "sh", "i"), - ("ザ", "z", "a"), - ("サ", "s", "a"), - ("ゴ", "g", "o"), - ("コ", "k", "o"), - ("ゲ", "g", "e"), - ("ケ", "k", "e"), - ("グヮ", "gw", "a"), - ("グ", "g", "u"), - ("クヮ", "kw", "a"), - ("ク", "k", "u"), - ("ギョ", "gy", "o"), - ("ギュ", "gy", "u"), - ("ギャ", "gy", "a"), - ("ギェ", "gy", "e"), - ("ギ", "g", "i"), - ("キョ", "ky", "o"), - ("キュ", "ky", "u"), - ("キャ", "ky", "a"), - ("キェ", "ky", "e"), - ("キ", "k", "i"), - ("ガ", "g", "a"), - ("カ", "k", "a"), - ("オ", None, "o"), - ("エ", None, "e"), - ("ウォ", "w", "o"), - ("ウェ", "w", "e"), - ("ウィ", "w", "i"), - ("ウ", None, "u"), - ("イェ", "y", "e"), - ("イ", None, "i"), - ("ア", None, "a"), -] -_mora_list_additional: list[tuple[str, Optional[str], str]] = [ - ("ヴョ", "by", "o"), - ("ヴュ", "by", "u"), - ("ヴャ", "by", "a"), - ("ヲ", None, "o"), - ("ヱ", None, "e"), - ("ヰ", None, "i"), - ("ヮ", "w", "a"), - ("ョ", "y", "o"), - ("ュ", "y", "u"), - ("ヅ", "z", "u"), - ("ヂ", "j", "i"), - ("ヶ", "k", "e"), - ("ャ", "y", "a"), - ("ォ", None, "o"), - ("ェ", None, "e"), - ("ゥ", None, "u"), - ("ィ", None, "i"), - ("ァ", None, "a"), -] - -# 例: "vo" -> "ヴォ", "a" -> "ア" -mora_phonemes_to_mora_kata: dict[str, str] = { - (consonant or "") + vowel: kana for [kana, consonant, vowel] in _mora_list_minimum -} - -# 例: "ヴォ" -> ("v", "o"), "ア" -> (None, "a") -mora_kata_to_mora_phonemes: dict[str, tuple[Optional[str], str]] = { - kana: (consonant, vowel) - for [kana, consonant, vowel] in _mora_list_minimum + _mora_list_additional -} diff --git a/text/symbols.py b/text/symbols.py deleted file mode 100644 index 846de64..0000000 --- a/text/symbols.py +++ /dev/null @@ -1,187 +0,0 @@ -punctuation = ["!", "?", "…", ",", ".", "'", "-"] -pu_symbols = punctuation + ["SP", "UNK"] -pad = "_" - -# chinese -zh_symbols = [ - "E", - "En", - "a", - "ai", - "an", - "ang", - "ao", - "b", - "c", - "ch", - "d", - "e", - "ei", - "en", - "eng", - "er", - "f", - "g", - "h", - "i", - "i0", - "ia", - "ian", - "iang", - "iao", - "ie", - "in", - "ing", - "iong", - "ir", - "iu", - "j", - "k", - "l", - "m", - "n", - "o", - "ong", - "ou", - "p", - "q", - "r", - "s", - "sh", - "t", - "u", - "ua", - "uai", - "uan", - "uang", - "ui", - "un", - "uo", - "v", - "van", - "ve", - "vn", - "w", - "x", - "y", - "z", - "zh", - "AA", - "EE", - "OO", -] -num_zh_tones = 6 - -# japanese -ja_symbols = [ - "N", - "a", - "a:", - "b", - "by", - "ch", - "d", - "dy", - "e", - "e:", - "f", - "g", - "gy", - "h", - "hy", - "i", - "i:", - "j", - "k", - "ky", - "m", - "my", - "n", - "ny", - "o", - "o:", - "p", - "py", - "q", - "r", - "ry", - "s", - "sh", - "t", - "ts", - "ty", - "u", - "u:", - "w", - "y", - "z", - "zy", -] -num_ja_tones = 2 - -# English -en_symbols = [ - "aa", - "ae", - "ah", - "ao", - "aw", - "ay", - "b", - "ch", - "d", - "dh", - "eh", - "er", - "ey", - "f", - "g", - "hh", - "ih", - "iy", - "jh", - "k", - "l", - "m", - "n", - "ng", - "ow", - "oy", - "p", - "r", - "s", - "sh", - "t", - "th", - "uh", - "uw", - "V", - "w", - "y", - "z", - "zh", -] -num_en_tones = 4 - -# combine all symbols -normal_symbols = sorted(set(zh_symbols + ja_symbols + en_symbols)) -symbols = [pad] + normal_symbols + pu_symbols -sil_phonemes_ids = [symbols.index(i) for i in pu_symbols] - -# combine all tones -num_tones = num_zh_tones + num_ja_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 = { - "ZH": 0, - "JP": num_zh_tones, - "EN": num_zh_tones + num_ja_tones, -} - -if __name__ == "__main__": - a = set(zh_symbols) - b = set(en_symbols) - print(sorted(a & b)) diff --git a/train_ms.py b/train_ms.py index 3e9e707..783b157 100644 --- a/train_ms.py +++ b/train_ms.py @@ -29,7 +29,7 @@ from data_utils import ( from losses import discriminator_loss, feature_loss, generator_loss, kl_loss from mel_processing import mel_spectrogram_torch, spec_to_mel_torch from models import DurationDiscriminator, MultiPeriodDiscriminator, SynthesizerTrn -from text.symbols import symbols +from style_bert_vits2.text_processing.symbols import SYMBOLS torch.backends.cuda.matmul.allow_tf32 = True torch.backends.cudnn.allow_tf32 = ( @@ -279,7 +279,7 @@ def run(): logger.info("Using normal encoder for VITS1") net_g = SynthesizerTrn( - len(symbols), + len(SYMBOLS), hps.data.filter_length // 2 + 1, hps.train.segment_size // hps.data.hop_length, n_speakers=hps.data.n_speakers, diff --git a/train_ms_jp_extra.py b/train_ms_jp_extra.py index 9a964c3..e4e4e56 100644 --- a/train_ms_jp_extra.py +++ b/train_ms_jp_extra.py @@ -34,7 +34,7 @@ from models_jp_extra import ( SynthesizerTrn, WavLMDiscriminator, ) -from text.symbols import symbols +from style_bert_vits2.text_processing.symbols import SYMBOLS torch.backends.cuda.matmul.allow_tf32 = True torch.backends.cudnn.allow_tf32 = ( @@ -293,7 +293,7 @@ def run(): logger.info("Using normal encoder for VITS1") net_g = SynthesizerTrn( - len(symbols), + len(SYMBOLS), hps.data.filter_length // 2 + 1, hps.train.segment_size // hps.data.hop_length, n_speakers=hps.data.n_speakers,