diff --git a/config.py b/config.py index 6369e6b..77c384d 100644 --- a/config.py +++ b/config.py @@ -11,6 +11,7 @@ import yaml from style_bert_vits2.logging import logger + # If not cuda available, set possible devices to cpu cuda_available = torch.cuda.is_available() diff --git a/data_utils.py b/data_utils.py index 04047e2..73d4303 100644 --- a/data_utils.py +++ b/data_utils.py @@ -15,6 +15,7 @@ from style_bert_vits2.models.hyper_parameters import HyperParametersData from style_bert_vits2.models.utils import load_filepaths_and_text, load_wav_to_torch from style_bert_vits2.nlp import cleaned_text_to_sequence + """Multi speaker version""" diff --git a/default_style.py b/default_style.py index 67b6fc3..e75257d 100644 --- a/default_style.py +++ b/default_style.py @@ -1,9 +1,10 @@ +import json import os -from style_bert_vits2.constants import DEFAULT_STYLE -from style_bert_vits2.logging import logger import numpy as np -import json + +from style_bert_vits2.constants import DEFAULT_STYLE +from style_bert_vits2.logging import logger def set_style_config(json_path, output_path): diff --git a/gen_yaml.py b/gen_yaml.py index 76df206..ac27103 100644 --- a/gen_yaml.py +++ b/gen_yaml.py @@ -1,6 +1,7 @@ import argparse import os import shutil + import yaml diff --git a/mel_processing.py b/mel_processing.py index e9e7ec3..02cd7d4 100644 --- a/mel_processing.py +++ b/mel_processing.py @@ -1,7 +1,9 @@ +import warnings + import torch import torch.utils.data from librosa.filters import mel as librosa_mel_fn -import warnings + # warnings.simplefilter(action='ignore', category=FutureWarning) warnings.filterwarnings(action="ignore") diff --git a/preprocess_all.py b/preprocess_all.py index 62c0b4f..c41159c 100644 --- a/preprocess_all.py +++ b/preprocess_all.py @@ -1,7 +1,9 @@ import argparse -from webui.train import preprocess_all from multiprocessing import cpu_count +from webui.train import preprocess_all + + if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( diff --git a/preprocess_text.py b/preprocess_text.py index 4966305..ef2e259 100644 --- a/preprocess_text.py +++ b/preprocess_text.py @@ -12,6 +12,7 @@ from style_bert_vits2.logging import logger from style_bert_vits2.nlp import clean_text from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT + preprocess_text_config = config.preprocess_text_config diff --git a/resample.py b/resample.py index 7001af6..b63c64a 100644 --- a/resample.py +++ b/resample.py @@ -7,9 +7,10 @@ import pyloudnorm as pyln import soundfile from tqdm import tqdm +from config import config from style_bert_vits2.logging import logger from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT -from config import config + DEFAULT_BLOCK_SIZE: float = 0.400 # seconds diff --git a/server_fastapi.py b/server_fastapi.py index 1f60b3c..4ac4a7e 100644 --- a/server_fastapi.py +++ b/server_fastapi.py @@ -38,6 +38,7 @@ from style_bert_vits2.nlp import bert_models from style_bert_vits2.nlp.japanese import pyopenjtalk_worker as pyopenjtalk from style_bert_vits2.tts_model import TTSModel, TTSModelHolder + ln = config.server_config.language diff --git a/slice.py b/slice.py index c69f8bf..fb5bb71 100644 --- a/slice.py +++ b/slice.py @@ -11,6 +11,7 @@ from tqdm import tqdm from style_bert_vits2.logging import logger from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT + vad_model, utils = torch.hub.load( repo_or_dir="snakers4/silero-vad", model="silero_vad", diff --git a/speech_mos.py b/speech_mos.py index 6dd2caa..453b7d3 100644 --- a/speech_mos.py +++ b/speech_mos.py @@ -14,6 +14,7 @@ from config import config from style_bert_vits2.logging import logger from style_bert_vits2.tts_model import TTSModel + warnings.filterwarnings("ignore") mos_result_dir = Path("mos_results") diff --git a/style_bert_vits2/models/attentions.py b/style_bert_vits2/models/attentions.py index 9a10112..b851b53 100644 --- a/style_bert_vits2/models/attentions.py +++ b/style_bert_vits2/models/attentions.py @@ -1,6 +1,6 @@ +import math from typing import Any, Optional -import math import torch from torch import nn from torch.nn import functional as F diff --git a/style_bert_vits2/models/commons.py b/style_bert_vits2/models/commons.py index da89930..38f548c 100644 --- a/style_bert_vits2/models/commons.py +++ b/style_bert_vits2/models/commons.py @@ -3,9 +3,10 @@ コードと完全に一致している保証はない。あくまで参考程度とすること。 """ +from typing import Any, Optional, Union + import torch from torch.nn import functional as F -from typing import Any, Optional, Union def init_weights(m: torch.nn.Module, mean: float = 0.0, std: float = 0.01) -> None: diff --git a/style_bert_vits2/models/infer.py b/style_bert_vits2/models/infer.py index b0ab9d2..a9bcbf6 100644 --- a/style_bert_vits2/models/infer.py +++ b/style_bert_vits2/models/infer.py @@ -1,12 +1,11 @@ -from typing import Any, cast, Optional, Union +from typing import Any, Optional, Union, cast import torch from numpy.typing import NDArray from style_bert_vits2.constants import Languages from style_bert_vits2.logging import logger -from style_bert_vits2.models import commons -from style_bert_vits2.models import utils +from style_bert_vits2.models import commons, utils from style_bert_vits2.models.hyper_parameters import HyperParameters from style_bert_vits2.models.models import SynthesizerTrn from style_bert_vits2.models.models_jp_extra import ( diff --git a/style_bert_vits2/models/models.py b/style_bert_vits2/models/models.py index 21a0be4..56fb27c 100644 --- a/style_bert_vits2/models/models.py +++ b/style_bert_vits2/models/models.py @@ -7,10 +7,7 @@ from torch.nn import Conv1d, Conv2d, ConvTranspose1d from torch.nn import functional as F from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm -from style_bert_vits2.models import attentions -from style_bert_vits2.models import commons -from style_bert_vits2.models import modules -from style_bert_vits2.models import monotonic_alignment +from style_bert_vits2.models import attentions, commons, modules, monotonic_alignment from style_bert_vits2.nlp.symbols import NUM_LANGUAGES, NUM_TONES, SYMBOLS diff --git a/style_bert_vits2/models/models_jp_extra.py b/style_bert_vits2/models/models_jp_extra.py index 00cc02f..2850baf 100644 --- a/style_bert_vits2/models/models_jp_extra.py +++ b/style_bert_vits2/models/models_jp_extra.py @@ -7,10 +7,7 @@ from torch.nn import Conv1d, Conv2d, ConvTranspose1d from torch.nn import functional as F from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm -from style_bert_vits2.models import attentions -from style_bert_vits2.models import commons -from style_bert_vits2.models import modules -from style_bert_vits2.models import monotonic_alignment +from style_bert_vits2.models import attentions, commons, modules, monotonic_alignment from style_bert_vits2.nlp.symbols import NUM_LANGUAGES, NUM_TONES, SYMBOLS diff --git a/style_bert_vits2/models/monotonic_alignment.py b/style_bert_vits2/models/monotonic_alignment.py index d33631e..8ec9d24 100644 --- a/style_bert_vits2/models/monotonic_alignment.py +++ b/style_bert_vits2/models/monotonic_alignment.py @@ -3,10 +3,11 @@ コードと完全に一致している保証はない。あくまで参考程度とすること。 """ +from typing import Any + import numba import torch -from numpy import int32, float32, zeros -from typing import Any +from numpy import float32, int32, zeros def maximum_path(neg_cent: torch.Tensor, mask: torch.Tensor) -> torch.Tensor: diff --git a/style_bert_vits2/models/utils/__init__.py b/style_bert_vits2/models/utils/__init__.py index 0fd3a47..f178372 100644 --- a/style_bert_vits2/models/utils/__init__.py +++ b/style_bert_vits2/models/utils/__init__.py @@ -4,7 +4,7 @@ import os import re import subprocess from pathlib import Path -from typing import Any, Optional, Union, TYPE_CHECKING +from typing import TYPE_CHECKING, Any, Optional, Union import numpy as np import torch @@ -15,6 +15,7 @@ from style_bert_vits2.logging import logger from style_bert_vits2.models.utils import checkpoints # type: ignore from style_bert_vits2.models.utils import safetensors # type: ignore + if TYPE_CHECKING: # tensorboard はライブラリとしてインストールされている場合は依存関係に含まれないため、型チェック時のみインポートする from torch.utils.tensorboard import SummaryWriter diff --git a/style_bert_vits2/nlp/__init__.py b/style_bert_vits2/nlp/__init__.py index 5f3d63f..b0c908e 100644 --- a/style_bert_vits2/nlp/__init__.py +++ b/style_bert_vits2/nlp/__init__.py @@ -1,4 +1,4 @@ -from typing import Optional, TYPE_CHECKING +from typing import TYPE_CHECKING, Optional from style_bert_vits2.constants import Languages from style_bert_vits2.nlp.symbols import ( @@ -7,6 +7,7 @@ from style_bert_vits2.nlp.symbols import ( SYMBOLS, ) + # __init__.py は配下のモジュールをインポートした時点で実行される # PyTorch のインポートは重いので、型チェック時以外はインポートしない if TYPE_CHECKING: @@ -99,10 +100,10 @@ def cleaned_text_to_sequence( cleaned_phones: list[str], tones: list[int], language: Languages ) -> tuple[list[int], list[int], list[int]]: """ - テキスト文字列を、テキスト内の記号に対応する一連の ID に変換する + 音素リスト・アクセントリスト・言語を、テキスト内の対応する ID に変換する Args: - cleaned_phones (list[str]): clean_text() でクリーニングされた音素のリスト (?) + cleaned_phones (list[str]): clean_text() でクリーニングされた音素のリスト tones (list[int]): 各音素のアクセント language (Languages): テキストの言語 diff --git a/style_bert_vits2/nlp/bert_models.py b/style_bert_vits2/nlp/bert_models.py index 220d584..1e346a4 100644 --- a/style_bert_vits2/nlp/bert_models.py +++ b/style_bert_vits2/nlp/bert_models.py @@ -9,7 +9,7 @@ Style-Bert-VITS2 の学習・推論に必要な各言語ごとの BERT モデル """ import gc -from typing import cast, Optional, Union +from typing import Optional, Union, cast import torch from transformers import ( diff --git a/style_bert_vits2/nlp/chinese/g2p.py b/style_bert_vits2/nlp/chinese/g2p.py index b5744cd..0046167 100644 --- a/style_bert_vits2/nlp/chinese/g2p.py +++ b/style_bert_vits2/nlp/chinese/g2p.py @@ -2,7 +2,7 @@ import re from pathlib import Path import jieba.posseg as psg -from pypinyin import lazy_pinyin, Style +from pypinyin import Style, lazy_pinyin from style_bert_vits2.nlp.chinese.tone_sandhi import ToneSandhi from style_bert_vits2.nlp.symbols import PUNCTUATIONS diff --git a/style_bert_vits2/nlp/chinese/tone_sandhi.py b/style_bert_vits2/nlp/chinese/tone_sandhi.py index 5832434..552cb0d 100644 --- a/style_bert_vits2/nlp/chinese/tone_sandhi.py +++ b/style_bert_vits2/nlp/chinese/tone_sandhi.py @@ -13,8 +13,7 @@ # limitations under the License. import jieba -from pypinyin import lazy_pinyin -from pypinyin import Style +from pypinyin import Style, lazy_pinyin class ToneSandhi: diff --git a/style_bert_vits2/nlp/japanese/normalizer.py b/style_bert_vits2/nlp/japanese/normalizer.py index b8cad90..07b742c 100644 --- a/style_bert_vits2/nlp/japanese/normalizer.py +++ b/style_bert_vits2/nlp/japanese/normalizer.py @@ -1,5 +1,6 @@ import re import unicodedata + from num2words import num2words from style_bert_vits2.nlp.symbols import PUNCTUATIONS diff --git a/style_bert_vits2/nlp/japanese/user_dict/__init__.py b/style_bert_vits2/nlp/japanese/user_dict/__init__.py index 2a4aa2f..53ea63f 100644 --- a/style_bert_vits2/nlp/japanese/user_dict/__init__.py +++ b/style_bert_vits2/nlp/japanese/user_dict/__init__.py @@ -17,12 +17,13 @@ from fastapi import HTTPException from style_bert_vits2.constants import DEFAULT_USER_DICT_DIR from style_bert_vits2.nlp.japanese import pyopenjtalk_worker as pyopenjtalk -from style_bert_vits2.nlp.japanese.user_dict.word_model import UserDictWord, WordTypes from style_bert_vits2.nlp.japanese.user_dict.part_of_speech_data import ( MAX_PRIORITY, MIN_PRIORITY, part_of_speech_data, ) +from style_bert_vits2.nlp.japanese.user_dict.word_model import UserDictWord, WordTypes + # root_dir = engine_root() # save_dir = get_save_dir() diff --git a/style_bert_vits2/nlp/japanese/user_dict/part_of_speech_data.py b/style_bert_vits2/nlp/japanese/user_dict/part_of_speech_data.py index 443bdc5..a48f0c5 100644 --- a/style_bert_vits2/nlp/japanese/user_dict/part_of_speech_data.py +++ b/style_bert_vits2/nlp/japanese/user_dict/part_of_speech_data.py @@ -14,6 +14,7 @@ from style_bert_vits2.nlp.japanese.user_dict.word_model import ( WordTypes, ) + MIN_PRIORITY = USER_DICT_MIN_PRIORITY MAX_PRIORITY = USER_DICT_MAX_PRIORITY diff --git a/style_bert_vits2/nlp/japanese/user_dict/word_model.py b/style_bert_vits2/nlp/japanese/user_dict/word_model.py index bcd4d37..c85a5b9 100644 --- a/style_bert_vits2/nlp/japanese/user_dict/word_model.py +++ b/style_bert_vits2/nlp/japanese/user_dict/word_model.py @@ -11,6 +11,7 @@ from typing import List, Optional from pydantic import BaseModel, Field, validator + USER_DICT_MIN_PRIORITY = 0 USER_DICT_MAX_PRIORITY = 10 diff --git a/style_gen.py b/style_gen.py index 5190575..f9685cf 100644 --- a/style_gen.py +++ b/style_gen.py @@ -1,6 +1,6 @@ import argparse -from concurrent.futures import ThreadPoolExecutor import warnings +from concurrent.futures import ThreadPoolExecutor import numpy as np import torch @@ -11,9 +11,11 @@ from style_bert_vits2.logging import logger from style_bert_vits2.models.hyper_parameters import HyperParameters from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT + warnings.filterwarnings("ignore", category=UserWarning) from pyannote.audio import Inference, Model + model = Model.from_pretrained("pyannote/wespeaker-voxceleb-resnet34-LM") inference = Inference(model, window="whole") device = torch.device(config.style_gen_config.device) diff --git a/train_ms.py b/train_ms.py index 50a2453..c1a392e 100644 --- a/train_ms.py +++ b/train_ms.py @@ -24,8 +24,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 style_bert_vits2.logging import logger -from style_bert_vits2.models import commons -from style_bert_vits2.models import utils +from style_bert_vits2.models import commons, utils from style_bert_vits2.models.hyper_parameters import HyperParameters from style_bert_vits2.models.models import ( DurationDiscriminator, @@ -35,6 +34,7 @@ from style_bert_vits2.models.models import ( from style_bert_vits2.nlp.symbols import SYMBOLS from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT + torch.backends.cuda.matmul.allow_tf32 = True torch.backends.cudnn.allow_tf32 = ( True # If encontered training problem,please try to disable TF32. diff --git a/train_ms_jp_extra.py b/train_ms_jp_extra.py index 321a040..722a521 100644 --- a/train_ms_jp_extra.py +++ b/train_ms_jp_extra.py @@ -24,8 +24,7 @@ from data_utils import ( from losses import WavLMLoss, discriminator_loss, feature_loss, generator_loss, kl_loss from mel_processing import mel_spectrogram_torch, spec_to_mel_torch from style_bert_vits2.logging import logger -from style_bert_vits2.models import commons -from style_bert_vits2.models import utils +from style_bert_vits2.models import commons, utils from style_bert_vits2.models.hyper_parameters import HyperParameters from style_bert_vits2.models.models_jp_extra import ( DurationDiscriminator, @@ -36,6 +35,7 @@ from style_bert_vits2.models.models_jp_extra import ( from style_bert_vits2.nlp.symbols import SYMBOLS from style_bert_vits2.utils.stdout_wrapper import SAFE_STDOUT + torch.backends.cuda.matmul.allow_tf32 = True torch.backends.cudnn.allow_tf32 = ( True # If encontered training problem,please try to disable TF32.