diff --git a/TTS/bin/train_encoder.py b/TTS/bin/train_encoder.py index 8d377db241..914c729856 100644 --- a/TTS/bin/train_encoder.py +++ b/TTS/bin/train_encoder.py @@ -296,7 +296,7 @@ def main(args): # pylint: disable=redefined-outer-name criterion, args.restore_step = model.load_checkpoint( c, args.restore_path, eval=False, use_cuda=use_cuda, criterion=criterion ) - print(" > Model restored from step %d" % args.restore_step, flush=True) + print(f" > Model restored from step {args.restore_step}", flush=True) else: args.restore_step = 0 diff --git a/TTS/config/__init__.py b/TTS/config/__init__.py index e47a141c73..401003504e 100644 --- a/TTS/config/__init__.py +++ b/TTS/config/__init__.py @@ -1,7 +1,7 @@ import json import os import re -from typing import Any, Dict, Union +from typing import Any, Union import fsspec import yaml @@ -58,7 +58,7 @@ def _process_model_name(config_dict: dict) -> str: """Format the model name as expected. It is a band-aid for the old `vocoder` model names. Args: - config_dict (Dict): A dictionary including the config fields. + config_dict (dict): A dictionary including the config fields. Returns: str: Formatted modelname. diff --git a/TTS/encoder/models/base_encoder.py b/TTS/encoder/models/base_encoder.py index 603481cc56..c6680c3a25 100644 --- a/TTS/encoder/models/base_encoder.py +++ b/TTS/encoder/models/base_encoder.py @@ -34,7 +34,7 @@ class BaseEncoder(nn.Module): # pylint: disable=W0102 def __init__(self): - super(BaseEncoder, self).__init__() + super().__init__() def get_torch_mel_spectrogram_class(self, audio_config): return torch.nn.Sequential( @@ -107,7 +107,7 @@ def get_criterion(self, c: Coqpit, num_classes=None): elif c.loss == "softmaxproto": criterion = SoftmaxAngleProtoLoss(c.model_params["proj_dim"], num_classes) else: - raise Exception("The %s not is a loss supported" % c.loss) + raise Exception(f"The {c.loss} not is a loss supported") return criterion def load_checkpoint( diff --git a/TTS/encoder/models/resnet.py b/TTS/encoder/models/resnet.py index 5eafcd6005..d7f3a2f4bd 100644 --- a/TTS/encoder/models/resnet.py +++ b/TTS/encoder/models/resnet.py @@ -7,7 +7,7 @@ class SELayer(nn.Module): def __init__(self, channel, reduction=8): - super(SELayer, self).__init__() + super().__init__() self.avg_pool = nn.AdaptiveAvgPool2d(1) self.fc = nn.Sequential( nn.Linear(channel, channel // reduction), @@ -27,7 +27,7 @@ class SEBasicBlock(nn.Module): expansion = 1 def __init__(self, inplanes, planes, stride=1, downsample=None, reduction=8): - super(SEBasicBlock, self).__init__() + super().__init__() self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=stride, padding=1, bias=False) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, padding=1, bias=False) @@ -73,7 +73,7 @@ def __init__( use_torch_spec=False, audio_config=None, ): - super(ResNetSpeakerEncoder, self).__init__() + super().__init__() self.encoder_type = encoder_type self.input_dim = input_dim diff --git a/TTS/encoder/utils/prepare_voxceleb.py b/TTS/encoder/utils/prepare_voxceleb.py index 18ca21c876..fe57874a99 100644 --- a/TTS/encoder/utils/prepare_voxceleb.py +++ b/TTS/encoder/utils/prepare_voxceleb.py @@ -82,17 +82,17 @@ def download_and_extract(directory, subset, urls): continue logger.info("Downloading %s to %s", url, zip_filepath) subprocess.call( - "wget %s --user %s --password %s -O %s" % (url, USER["user"], USER["password"], zip_filepath), + "wget {} --user {} --password {} -O {}".format(url, USER["user"], USER["password"], zip_filepath), shell=True, ) statinfo = os.stat(zip_filepath) - logger.info("Successfully downloaded %s, size(bytes): %d" % (url, statinfo.st_size)) + logger.info("Successfully downloaded %s, size(bytes): %d", url, statinfo.st_size) # concatenate all parts into zip files if ".zip" not in zip_filepath: zip_filepath = "_".join(zip_filepath.split("_")[:-1]) - subprocess.call("cat %s* > %s.zip" % (zip_filepath, zip_filepath), shell=True) + subprocess.call(f"cat {zip_filepath}* > {zip_filepath}.zip", shell=True) zip_filepath += ".zip" extract_path = zip_filepath.strip(".zip") @@ -100,12 +100,12 @@ def download_and_extract(directory, subset, urls): with open(zip_filepath, "rb") as f_zip: md5 = hashlib.md5(f_zip.read()).hexdigest() if md5 != MD5SUM[subset]: - raise ValueError("md5sum of %s mismatch" % zip_filepath) + raise ValueError(f"md5sum of {zip_filepath} mismatch") with zipfile.ZipFile(zip_filepath, "r") as zfile: zfile.extractall(directory) extract_path_ori = os.path.join(directory, zfile.infolist()[0].filename) - subprocess.call("mv %s %s" % (extract_path_ori, extract_path), shell=True) + subprocess.call(f"mv {extract_path_ori} {extract_path}", shell=True) finally: # os.remove(zip_filepath) pass @@ -193,7 +193,7 @@ def convert_audio_and_make_label(input_dir, subset, output_dir, output_file): writer.writerow(["wav_filename", "wav_length_ms", "speaker_id", "speaker_name"]) for wav_file in files: writer.writerow(wav_file) - logger.info(f"Successfully generated csv file {csv_file_path}") + logger.info("Successfully generated csv file %s", csv_file_path) def processor(directory, subset, force_process): diff --git a/TTS/tts/datasets/__init__.py b/TTS/tts/datasets/__init__.py index a99eb4290d..2f5357c642 100644 --- a/TTS/tts/datasets/__init__.py +++ b/TTS/tts/datasets/__init__.py @@ -4,7 +4,6 @@ from collections import Counter from collections.abc import Callable from pathlib import Path -from typing import Dict, List, Tuple, Union import numpy as np @@ -18,7 +17,7 @@ def split_dataset(items, eval_split_max_size=None, eval_split_size=0.01): """Split a dataset into train and eval. Consider speaker distribution in multi-speaker training. Args: - items (List[List]): + items (list[list]): A list of samples. Each sample is a list of `[audio_path, text, speaker_id]`. eval_split_max_size (int): @@ -76,12 +75,12 @@ def load_tts_samples( eval_split_max_size=None, eval_split_size=0.01, ) -> tuple[list[list], list[list]]: - """Parse the dataset from the datasets config, load the samples as a List and load the attention alignments if provided. + """Parse the dataset from the datasets config, load the samples as a list and load the attention alignments if provided. If `formatter` is not None, apply the formatter to the samples else pick the formatter from the available ones based on the dataset name. Args: - datasets (List[Dict], Dict): A list of datasets or a single dataset dictionary. If multiple datasets are + datasets (list[dict], dict): A list of datasets or a single dataset dictionary. If multiple datasets are in the list, they are all merged. eval_split (bool, optional): If true, create a evaluation split. If an eval split provided explicitly, generate @@ -100,7 +99,7 @@ def load_tts_samples( If > 1, represents the absolute number of evaluation samples. Defaults to 0.01 (1%). Returns: - Tuple[List[List], List[List]: training and evaluation splits of the dataset. + tuple[list[list], list[list]: training and evaluation splits of the dataset. """ meta_data_train_all = [] meta_data_eval_all = [] if eval_split else None diff --git a/TTS/tts/layers/delightful_tts/conv_layers.py b/TTS/tts/layers/delightful_tts/conv_layers.py index 588d236852..5cf41d4ff6 100644 --- a/TTS/tts/layers/delightful_tts/conv_layers.py +++ b/TTS/tts/layers/delightful_tts/conv_layers.py @@ -50,7 +50,7 @@ def __init__( w_init_gain="linear", use_weight_norm=False, ): - super(ConvNorm, self).__init__() # pylint: disable=super-with-arguments + super().__init__() if padding is None: assert kernel_size % 2 == 1 padding = int(dilation * (kernel_size - 1) / 2) @@ -92,7 +92,7 @@ def __init__( lstm_type="bilstm", use_linear=True, ): - super(ConvLSTMLinear, self).__init__() # pylint: disable=super-with-arguments + super().__init__() self.out_dim = out_dim self.lstm_type = lstm_type self.use_linear = use_linear diff --git a/TTS/tts/layers/delightful_tts/networks.py b/TTS/tts/layers/delightful_tts/networks.py index d0a4adae79..93b65a2a74 100644 --- a/TTS/tts/layers/delightful_tts/networks.py +++ b/TTS/tts/layers/delightful_tts/networks.py @@ -51,7 +51,7 @@ def __init__( kernel_size=3, use_partial_padding=False, # pylint: disable=unused-argument ): - super(BottleneckLayer, self).__init__() # pylint: disable=super-with-arguments + super().__init__() self.reduction_factor = reduction_factor reduced_dim = int(in_dim / reduction_factor) @@ -194,7 +194,7 @@ class STL(nn.Module): """ def __init__(self, n_hidden: int, token_num: int): - super(STL, self).__init__() # pylint: disable=super-with-arguments + super().__init__() num_heads = 1 E = n_hidden diff --git a/TTS/tts/layers/tortoise/diffusion.py b/TTS/tts/layers/tortoise/diffusion.py index 2b29091b44..cfb8fa800d 100644 --- a/TTS/tts/layers/tortoise/diffusion.py +++ b/TTS/tts/layers/tortoise/diffusion.py @@ -653,7 +653,7 @@ def p_sample_loop_progressive( """ if device is None: device = next(model.parameters()).device - assert isinstance(shape, (tuple, list)) + assert isinstance(shape, tuple | list) if noise is not None: img = noise else: @@ -805,7 +805,7 @@ def ddim_sample_loop_progressive( """ if device is None: device = next(model.parameters()).device - assert isinstance(shape, (tuple, list)) + assert isinstance(shape, tuple | list) if noise is not None: img = noise else: diff --git a/TTS/tts/layers/tortoise/vocoder.py b/TTS/tts/layers/tortoise/vocoder.py index 6fd784f486..e7497d8190 100644 --- a/TTS/tts/layers/tortoise/vocoder.py +++ b/TTS/tts/layers/tortoise/vocoder.py @@ -293,7 +293,7 @@ def __init__( hop_length=256, n_mel_channels=100, ): - super(UnivNetGenerator, self).__init__() + super().__init__() self.mel_channel = n_mel_channels self.noise_dim = noise_dim self.hop_length = hop_length @@ -344,7 +344,7 @@ def forward(self, c, z): return z def eval(self, inference=False): - super(UnivNetGenerator, self).eval() + super().eval() # don't remove weight norm while validation in training loop if inference: self.remove_weight_norm() diff --git a/TTS/tts/layers/xtts/tokenizer.py b/TTS/tts/layers/xtts/tokenizer.py index 8af4e78a40..ef4162a1cb 100644 --- a/TTS/tts/layers/xtts/tokenizer.py +++ b/TTS/tts/layers/xtts/tokenizer.py @@ -76,7 +76,7 @@ def split_sentence(text, lang, text_split_length=250): # List of (regular expression, replacement) pairs for abbreviations: _abbreviations = { "en": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("mrs", "misess"), ("mr", "mister"), @@ -99,7 +99,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "es": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("sra", "señora"), ("sr", "señor"), @@ -112,7 +112,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "fr": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("mme", "madame"), ("mr", "monsieur"), @@ -124,7 +124,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "de": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("fr", "frau"), ("dr", "doktor"), @@ -134,7 +134,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "pt": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("sra", "senhora"), ("sr", "senhor"), @@ -147,7 +147,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "it": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ # ("sig.ra", "signora"), ("sig", "signore"), @@ -159,7 +159,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "pl": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("p", "pani"), ("m", "pan"), @@ -169,19 +169,19 @@ def split_sentence(text, lang, text_split_length=250): ] ], "ar": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ # There are not many common abbreviations in Arabic as in English. ] ], "zh": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ # Chinese doesn't typically use abbreviations in the same way as Latin-based scripts. ] ], "cs": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("dr", "doktor"), # doctor ("ing", "inženýr"), # engineer @@ -190,7 +190,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "ru": [ - (re.compile("\\b%s\\b" % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\b", re.IGNORECASE), x[1]) for x in [ ("г-жа", "госпожа"), # Mrs. ("г-н", "господин"), # Mr. @@ -199,7 +199,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "nl": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("dhr", "de heer"), # Mr. ("mevr", "mevrouw"), # Mrs. @@ -209,7 +209,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "tr": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("b", "bay"), # Mr. ("byk", "büyük"), # büyük @@ -218,7 +218,7 @@ def split_sentence(text, lang, text_split_length=250): ] ], "hu": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("dr", "doktor"), # doctor ("b", "bácsi"), # Mr. @@ -227,13 +227,13 @@ def split_sentence(text, lang, text_split_length=250): ] ], "ko": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ # Korean doesn't typically use abbreviations in the same way as Latin-based scripts. ] ], "hi": [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ # Hindi doesn't typically use abbreviations in the same way as Latin-based scripts. ] @@ -249,7 +249,7 @@ def expand_abbreviations_multilingual(text, lang="en"): _symbols_multilingual = { "en": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " and "), ("@", " at "), @@ -261,7 +261,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ] ], "es": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " y "), ("@", " arroba "), @@ -273,7 +273,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ] ], "fr": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " et "), ("@", " arobase "), @@ -285,7 +285,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ] ], "de": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " und "), ("@", " at "), @@ -297,7 +297,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ] ], "pt": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " e "), ("@", " arroba "), @@ -309,7 +309,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ] ], "it": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " e "), ("@", " chiocciola "), @@ -321,7 +321,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ] ], "pl": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " i "), ("@", " małpa "), @@ -334,7 +334,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ], "ar": [ # Arabic - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " و "), ("@", " على "), @@ -347,7 +347,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ], "zh": [ # Chinese - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " 和 "), ("@", " 在 "), @@ -360,7 +360,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ], "cs": [ # Czech - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " a "), ("@", " na "), @@ -373,7 +373,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ], "ru": [ # Russian - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " и "), ("@", " собака "), @@ -386,7 +386,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ], "nl": [ # Dutch - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " en "), ("@", " bij "), @@ -398,7 +398,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ] ], "tr": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " ve "), ("@", " at "), @@ -410,7 +410,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ] ], "hu": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " és "), ("@", " kukac "), @@ -423,7 +423,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ], "ko": [ # Korean - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " 그리고 "), ("@", " 에 "), @@ -435,7 +435,7 @@ def expand_abbreviations_multilingual(text, lang="en"): ] ], "hi": [ - (re.compile(r"%s" % re.escape(x[0]), re.IGNORECASE), x[1]) + (re.compile(rf"{re.escape(x[0])}", re.IGNORECASE), x[1]) for x in [ ("&", " और "), ("@", " ऐट दी रेट "), diff --git a/TTS/tts/layers/xtts/trainer/gpt_trainer.py b/TTS/tts/layers/xtts/trainer/gpt_trainer.py index 757d1649c2..e00ce2b4de 100644 --- a/TTS/tts/layers/xtts/trainer/gpt_trainer.py +++ b/TTS/tts/layers/xtts/trainer/gpt_trainer.py @@ -430,7 +430,7 @@ def get_optimizer(self) -> list: v.is_norm = isinstance(m, norm_modules) v.is_emb = isinstance(m, emb_modules) - fpn = "%s.%s" % (mn, k) if mn else k # full param name + fpn = f"{mn}.{k}" if mn else k # full param name all_param_names.add(fpn) param_map[fpn] = v if v.is_bias or v.is_norm or v.is_emb: diff --git a/TTS/tts/layers/xtts/zh_num2words.py b/TTS/tts/layers/xtts/zh_num2words.py index f0a1db786d..360d9b06c8 100644 --- a/TTS/tts/layers/xtts/zh_num2words.py +++ b/TTS/tts/layers/xtts/zh_num2words.py @@ -420,7 +420,7 @@ class ChineseNumberUnit(ChineseChar): """ def __init__(self, power, simplified, traditional, big_s, big_t): - super(ChineseNumberUnit, self).__init__(simplified, traditional) + super().__init__(simplified, traditional) self.power = power self.big_s = big_s self.big_t = big_t @@ -456,7 +456,7 @@ class ChineseNumberDigit(ChineseChar): """ def __init__(self, value, simplified, traditional, big_s, big_t, alt_s=None, alt_t=None): - super(ChineseNumberDigit, self).__init__(simplified, traditional) + super().__init__(simplified, traditional) self.value = value self.big_s = big_s self.big_t = big_t @@ -477,7 +477,7 @@ class ChineseMath(ChineseChar): """ def __init__(self, simplified, traditional, symbol, expression=None): - super(ChineseMath, self).__init__(simplified, traditional) + super().__init__(simplified, traditional) self.symbol = symbol self.expression = expression self.big_s = simplified @@ -507,8 +507,7 @@ def __init__(self, positive, negative, point): self.point = point def __iter__(self): - for v in self.__dict__.values(): - yield v + yield from self.__dict__.values() # class OtherSymbol(object): @@ -702,7 +701,7 @@ def get_value(value_string, use_zeros=True): if isinstance(v, CND) and v.value == 2: next_symbol = result_symbols[i + 1] if i < len(result_symbols) - 1 else None previous_symbol = result_symbols[i - 1] if i > 0 else None - if isinstance(next_symbol, CNU) and isinstance(previous_symbol, (CNU, type(None))): + if isinstance(next_symbol, CNU) and isinstance(previous_symbol, CNU | type(None)): if next_symbol.power != 1 and ((previous_symbol is None) or (previous_symbol.power != 1)): result_symbols[i] = liang diff --git a/TTS/tts/models/__init__.py b/TTS/tts/models/__init__.py index 0e1587b60b..4746b13ea2 100644 --- a/TTS/tts/models/__init__.py +++ b/TTS/tts/models/__init__.py @@ -1,5 +1,4 @@ import logging -from typing import Dict, List, Union from TTS.utils.generic_utils import find_module diff --git a/TTS/tts/utils/text/cmudict.py b/TTS/tts/utils/text/cmudict.py index 041b42ff31..9c0df06196 100644 --- a/TTS/tts/utils/text/cmudict.py +++ b/TTS/tts/utils/text/cmudict.py @@ -119,7 +119,7 @@ def get_arpabet(word, cmudict, punctuation_symbols): word = word[:-1] arpabet = cmudict.lookup(word) if arpabet is not None: - return first_symbol + "{%s}" % arpabet[0] + last_symbol + return first_symbol + "{%s}" % arpabet[0] + last_symbol # noqa: UP031 return first_symbol + word + last_symbol diff --git a/TTS/tts/utils/text/english/abbreviations.py b/TTS/tts/utils/text/english/abbreviations.py index cd93c13c8e..20042b255b 100644 --- a/TTS/tts/utils/text/english/abbreviations.py +++ b/TTS/tts/utils/text/english/abbreviations.py @@ -2,7 +2,7 @@ # List of (regular expression, replacement) pairs for abbreviations in english: abbreviations_en = [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("mrs", "misess"), ("mr", "mister"), diff --git a/TTS/tts/utils/text/french/abbreviations.py b/TTS/tts/utils/text/french/abbreviations.py index f580dfed7b..e317bbbf3a 100644 --- a/TTS/tts/utils/text/french/abbreviations.py +++ b/TTS/tts/utils/text/french/abbreviations.py @@ -2,7 +2,7 @@ # List of (regular expression, replacement) pairs for abbreviations in french: abbreviations_fr = [ - (re.compile("\\b%s\\." % x[0], re.IGNORECASE), x[1]) + (re.compile(f"\\b{x[0]}\\.", re.IGNORECASE), x[1]) for x in [ ("M", "monsieur"), ("Mlle", "mademoiselle"), @@ -38,7 +38,7 @@ ("boul", "boulevard"), ] ] + [ - (re.compile("\\b%s" % x[0]), x[1]) + (re.compile(f"\\b{x[0]}"), x[1]) for x in [ ("Mlle", "mademoiselle"), ("Mlles", "mesdemoiselles"), diff --git a/TTS/tts/utils/text/phonemizers/espeak_wrapper.py b/TTS/tts/utils/text/phonemizers/espeak_wrapper.py index 5c58afdf08..dbcb8994a7 100644 --- a/TTS/tts/utils/text/phonemizers/espeak_wrapper.py +++ b/TTS/tts/utils/text/phonemizers/espeak_wrapper.py @@ -183,7 +183,7 @@ def phonemize_espeak(self, text: str, separator: str = "|", *, tie: bool = False else: args.append("--ipa=1") if tie: - args.append("--tie=%s" % tie) + args.append(f"--tie={tie}") tmp = tempfile.NamedTemporaryFile(mode="w+t", delete=False, encoding="utf8") tmp.write(text) diff --git a/TTS/tts/utils/text/tokenizer.py b/TTS/tts/utils/text/tokenizer.py index 4d6c9e401e..07a8753884 100644 --- a/TTS/tts/utils/text/tokenizer.py +++ b/TTS/tts/utils/text/tokenizer.py @@ -164,7 +164,7 @@ def init_from_config(config: "Coqpit", characters: "BaseCharacters" = None): """ # init cleaners text_cleaner = None - if isinstance(config.text_cleaner, (str, list)): + if isinstance(config.text_cleaner, str | list): text_cleaner = getattr(cleaners, config.text_cleaner) # init characters diff --git a/TTS/utils/radam.py b/TTS/utils/radam.py index b5306d6ab3..b893d115c9 100644 --- a/TTS/utils/radam.py +++ b/TTS/utils/radam.py @@ -18,7 +18,7 @@ def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, weight_decay=0 raise ValueError(f"Invalid beta parameter at index 1: {betas[1]}") self.degenerated_to_sgd = degenerated_to_sgd - if isinstance(params, (list, tuple)) and len(params) > 0 and isinstance(params[0], dict): + if isinstance(params, list | tuple) and len(params) > 0 and isinstance(params[0], dict): for param in params: if "betas" in param and (param["betas"][0] != betas[0] or param["betas"][1] != betas[1]): param["buffer"] = [[None, None, None] for _ in range(10)] diff --git a/TTS/vc/layers/freevc/modules.py b/TTS/vc/layers/freevc/modules.py index c34f22d701..92df39b5e0 100644 --- a/TTS/vc/layers/freevc/modules.py +++ b/TTS/vc/layers/freevc/modules.py @@ -48,7 +48,7 @@ def forward(self, x, x_mask): class WN(torch.nn.Module): def __init__(self, hidden_channels, kernel_size, dilation_rate, n_layers, gin_channels=0, p_dropout=0): - super(WN, self).__init__() + super().__init__() assert kernel_size % 2 == 1 self.hidden_channels = hidden_channels self.kernel_size = (kernel_size,) @@ -122,7 +122,7 @@ def remove_weight_norm(self): class ResBlock1(torch.nn.Module): def __init__(self, channels, kernel_size=3, dilation=(1, 3, 5)): - super(ResBlock1, self).__init__() + super().__init__() self.convs1 = nn.ModuleList( [ weight_norm( @@ -198,7 +198,7 @@ def remove_weight_norm(self): class ResBlock2(torch.nn.Module): def __init__(self, channels, kernel_size=3, dilation=(1, 3)): - super(ResBlock2, self).__init__() + super().__init__() self.convs = nn.ModuleList( [ weight_norm( diff --git a/TTS/vc/layers/freevc/wavlm/modules.py b/TTS/vc/layers/freevc/wavlm/modules.py index 06348e4bb4..cddacd69ab 100644 --- a/TTS/vc/layers/freevc/wavlm/modules.py +++ b/TTS/vc/layers/freevc/wavlm/modules.py @@ -88,7 +88,7 @@ class Swish(nn.Module): def __init__(self): """Construct an MultiHeadedAttention object.""" - super(Swish, self).__init__() + super().__init__() self.act = torch.nn.Sigmoid() def forward(self, x): @@ -97,7 +97,7 @@ def forward(self, x): class GLU_Linear(nn.Module): def __init__(self, input_dim, output_dim, glu_type="sigmoid", bias_in_glu=True): - super(GLU_Linear, self).__init__() + super().__init__() self.glu_type = glu_type self.output_dim = output_dim @@ -218,7 +218,7 @@ def quant_noise(module, p, block_size): return module # supported modules - assert isinstance(module, (nn.Linear, nn.Embedding, nn.Conv2d)) + assert isinstance(module, nn.Linear | nn.Embedding | nn.Conv2d) # test whether module.weight has the right sizes wrt block_size is_conv = module.weight.ndim == 4 diff --git a/TTS/vc/models/__init__.py b/TTS/vc/models/__init__.py index 138178089f..4a1833bf50 100644 --- a/TTS/vc/models/__init__.py +++ b/TTS/vc/models/__init__.py @@ -1,7 +1,6 @@ import importlib import logging import re -from typing import Dict, List, Union logger = logging.getLogger(__name__) diff --git a/TTS/vc/models/freevc.py b/TTS/vc/models/freevc.py index 69fa40bdbc..7f132772ea 100644 --- a/TTS/vc/models/freevc.py +++ b/TTS/vc/models/freevc.py @@ -101,7 +101,7 @@ def __init__( upsample_kernel_sizes, gin_channels=0, ): - super(Generator, self).__init__() + super().__init__() self.num_kernels = len(resblock_kernel_sizes) self.num_upsamples = len(upsample_rates) self.conv_pre = Conv1d(initial_channel, upsample_initial_channel, 7, 1, padding=3) @@ -164,7 +164,7 @@ def remove_weight_norm(self): class MultiPeriodDiscriminator(torch.nn.Module): def __init__(self, use_spectral_norm=False): - super(MultiPeriodDiscriminator, self).__init__() + super().__init__() periods = [2, 3, 5, 7, 11] discs = [DiscriminatorS(use_spectral_norm=use_spectral_norm)] @@ -189,7 +189,7 @@ def forward(self, y, y_hat): class SpeakerEncoder(torch.nn.Module): def __init__(self, mel_n_channels=80, model_num_layers=3, model_hidden_size=256, model_embedding_size=256): - super(SpeakerEncoder, self).__init__() + super().__init__() self.lstm = nn.LSTM(mel_n_channels, model_hidden_size, model_num_layers, batch_first=True) self.linear = nn.Linear(model_hidden_size, model_embedding_size) self.relu = nn.ReLU() diff --git a/TTS/vocoder/datasets/__init__.py b/TTS/vocoder/datasets/__init__.py index d935209348..cef6a50b05 100644 --- a/TTS/vocoder/datasets/__init__.py +++ b/TTS/vocoder/datasets/__init__.py @@ -1,5 +1,3 @@ -from typing import List - from coqpit import Coqpit from torch.utils.data import Dataset diff --git a/TTS/vocoder/datasets/gan_dataset.py b/TTS/vocoder/datasets/gan_dataset.py index 0806c0d496..c0882c701f 100644 --- a/TTS/vocoder/datasets/gan_dataset.py +++ b/TTS/vocoder/datasets/gan_dataset.py @@ -32,7 +32,7 @@ def __init__( super().__init__() self.ap = ap self.item_list = items - self.compute_feat = not isinstance(items[0], (tuple, list)) + self.compute_feat = not isinstance(items[0], tuple | list) self.seq_len = seq_len self.hop_len = hop_len self.pad_short = pad_short diff --git a/TTS/vocoder/datasets/wavernn_dataset.py b/TTS/vocoder/datasets/wavernn_dataset.py index 4c4f5c48df..ffb71177c5 100644 --- a/TTS/vocoder/datasets/wavernn_dataset.py +++ b/TTS/vocoder/datasets/wavernn_dataset.py @@ -18,7 +18,7 @@ class WaveRNNDataset(Dataset): def __init__(self, ap, items, seq_len, hop_len, pad, mode, mulaw, is_training=True, return_segments=True): super().__init__() self.ap = ap - self.compute_feat = not isinstance(items[0], (tuple, list)) + self.compute_feat = not isinstance(items[0], tuple | list) self.item_list = items self.seq_len = seq_len self.hop_len = hop_len diff --git a/TTS/vocoder/layers/wavegrad.py b/TTS/vocoder/layers/wavegrad.py index 9f1512c6d4..187e7062e2 100644 --- a/TTS/vocoder/layers/wavegrad.py +++ b/TTS/vocoder/layers/wavegrad.py @@ -74,7 +74,7 @@ def shif_and_scale(x, scale, shift): class UBlock(nn.Module): def __init__(self, input_size, hidden_size, factor, dilation): super().__init__() - assert isinstance(dilation, (list, tuple)) + assert isinstance(dilation, list | tuple) assert len(dilation) == 4 self.factor = factor diff --git a/TTS/vocoder/models/parallel_wavegan_discriminator.py b/TTS/vocoder/models/parallel_wavegan_discriminator.py index 211d45d91c..02ad60e0ff 100644 --- a/TTS/vocoder/models/parallel_wavegan_discriminator.py +++ b/TTS/vocoder/models/parallel_wavegan_discriminator.py @@ -71,7 +71,7 @@ def forward(self, x): def apply_weight_norm(self): def _apply_weight_norm(m): - if isinstance(m, (torch.nn.Conv1d, torch.nn.Conv2d)): + if isinstance(m, torch.nn.Conv1d | torch.nn.Conv2d): torch.nn.utils.parametrizations.weight_norm(m) self.apply(_apply_weight_norm) @@ -174,7 +174,7 @@ def forward(self, x): def apply_weight_norm(self): def _apply_weight_norm(m): - if isinstance(m, (torch.nn.Conv1d, torch.nn.Conv2d)): + if isinstance(m, torch.nn.Conv1d | torch.nn.Conv2d): torch.nn.utils.parametrizations.weight_norm(m) self.apply(_apply_weight_norm) diff --git a/TTS/vocoder/models/parallel_wavegan_generator.py b/TTS/vocoder/models/parallel_wavegan_generator.py index 0659a00cc1..f4ef3a0734 100644 --- a/TTS/vocoder/models/parallel_wavegan_generator.py +++ b/TTS/vocoder/models/parallel_wavegan_generator.py @@ -145,7 +145,7 @@ def _remove_weight_norm(m): def apply_weight_norm(self): def _apply_weight_norm(m): - if isinstance(m, (torch.nn.Conv1d, torch.nn.Conv2d)): + if isinstance(m, torch.nn.Conv1d | torch.nn.Conv2d): torch.nn.utils.parametrizations.weight_norm(m) logger.info("Weight norm is applied to %s", m) diff --git a/TTS/vocoder/models/univnet_generator.py b/TTS/vocoder/models/univnet_generator.py index 82909231ee..d991941441 100644 --- a/TTS/vocoder/models/univnet_generator.py +++ b/TTS/vocoder/models/univnet_generator.py @@ -127,7 +127,7 @@ def apply_weight_norm(self): """Apply weight normalization module from all of the layers.""" def _apply_weight_norm(m): - if isinstance(m, (torch.nn.Conv1d, torch.nn.Conv2d)): + if isinstance(m, torch.nn.Conv1d | torch.nn.Conv2d): torch.nn.utils.parametrizations.weight_norm(m) logger.info("Weight norm is applied to %s", m) diff --git a/tests/tts_tests/test_tacotron_model.py b/tests/tts_tests/test_tacotron_model.py index e71baa574d..3976b9ae8d 100644 --- a/tests/tts_tests/test_tacotron_model.py +++ b/tests/tts_tests/test_tacotron_model.py @@ -51,7 +51,7 @@ def test_train_step(): criterion_st = nn.BCEWithLogitsLoss().to(device) model = Tacotron(config).to(device) # FIXME: missing num_speakers parameter to Tacotron ctor model.train() - print(" > Num parameters for Tacotron model:%s" % (count_parameters(model))) + print(f" > Num parameters for Tacotron model:{count_parameters(model)}") model_ref = copy.deepcopy(model) count = 0 for param, param_ref in zip(model.parameters(), model_ref.parameters()): @@ -105,7 +105,7 @@ def test_train_step(): config.d_vector_dim = 55 model = Tacotron(config).to(device) # FIXME: missing num_speakers parameter to Tacotron ctor model.train() - print(" > Num parameters for Tacotron model:%s" % (count_parameters(model))) + print(f" > Num parameters for Tacotron model:{count_parameters(model)}") model_ref = copy.deepcopy(model) count = 0 for param, param_ref in zip(model.parameters(), model_ref.parameters()): @@ -165,7 +165,7 @@ def test_train_step(): model = Tacotron(config).to(device) # FIXME: missing num_speakers parameter to Tacotron ctor model.train() # print(model) - print(" > Num parameters for Tacotron GST model:%s" % (count_parameters(model))) + print(f" > Num parameters for Tacotron GST model:{count_parameters(model)}") model_ref = copy.deepcopy(model) count = 0 for param, param_ref in zip(model.parameters(), model_ref.parameters()): @@ -217,7 +217,7 @@ def test_train_step(): model = Tacotron(config).to(device) # FIXME: missing num_speakers parameter to Tacotron ctor model.train() # print(model) - print(" > Num parameters for Tacotron GST model:%s" % (count_parameters(model))) + print(f" > Num parameters for Tacotron GST model:{count_parameters(model)}") model_ref = copy.deepcopy(model) count = 0 for param, param_ref in zip(model.parameters(), model_ref.parameters()): @@ -288,7 +288,7 @@ def test_train_step(): criterion = model.get_criterion() optimizer = model.get_optimizer() model.train() - print(" > Num parameters for Tacotron with Capacitron VAE model:%s" % (count_parameters(model))) + print(f" > Num parameters for Tacotron with Capacitron VAE model:{count_parameters(model)}") model_ref = copy.deepcopy(model) count = 0 for param, param_ref in zip(model.parameters(), model_ref.parameters()): @@ -341,7 +341,7 @@ def test_train_step(): config.d_vector_dim = 55 model = Tacotron(config).to(device) # FIXME: missing num_speakers parameter to Tacotron ctor model.train() - print(" > Num parameters for Tacotron model:%s" % (count_parameters(model))) + print(f" > Num parameters for Tacotron model:{count_parameters(model)}") model_ref = copy.deepcopy(model) count = 0 for param, param_ref in zip(model.parameters(), model_ref.parameters()): diff --git a/tests/tts_tests2/test_glow_tts.py b/tests/tts_tests2/test_glow_tts.py index d0557b6311..967e9ecb9e 100644 --- a/tests/tts_tests2/test_glow_tts.py +++ b/tests/tts_tests2/test_glow_tts.py @@ -107,7 +107,7 @@ def _test_forward(self, batch_size): config = GlowTTSConfig(num_chars=32) model = GlowTTS(config).to(device) model.train() - print(" > Num parameters for GlowTTS model:%s" % (count_parameters(model))) + print(f" > Num parameters for GlowTTS model:{count_parameters(model)}") # inference encoder and decoder with MAS y = model.forward(input_dummy, input_lengths, mel_spec, mel_lengths) self.assertEqual(y["z"].shape, mel_spec.shape) @@ -134,7 +134,7 @@ def _test_forward_with_d_vector(self, batch_size): ) model = GlowTTS.init_from_config(config).to(device) model.train() - print(" > Num parameters for GlowTTS model:%s" % (count_parameters(model))) + print(f" > Num parameters for GlowTTS model:{count_parameters(model)}") # inference encoder and decoder with MAS y = model.forward(input_dummy, input_lengths, mel_spec, mel_lengths, {"d_vectors": d_vector}) self.assertEqual(y["z"].shape, mel_spec.shape) @@ -160,7 +160,7 @@ def _test_forward_with_speaker_id(self, batch_size): ) model = GlowTTS.init_from_config(config).to(device) model.train() - print(" > Num parameters for GlowTTS model:%s" % (count_parameters(model))) + print(f" > Num parameters for GlowTTS model:{count_parameters(model)}") # inference encoder and decoder with MAS y = model.forward(input_dummy, input_lengths, mel_spec, mel_lengths, {"speaker_ids": speaker_ids}) self.assertEqual(y["z"].shape, mel_spec.shape) @@ -261,7 +261,7 @@ def test_train_step(self): # reference model to compare model weights model_ref = GlowTTS(config).to(device) model.train() - print(" > Num parameters for GlowTTS model:%s" % (count_parameters(model))) + print(f" > Num parameters for GlowTTS model:{count_parameters(model)}") # pass the state to ref model model_ref.load_state_dict(copy.deepcopy(model.state_dict())) count = 0 diff --git a/tests/vc_tests/test_freevc.py b/tests/vc_tests/test_freevc.py index fe07b2723c..dd45d6941f 100644 --- a/tests/vc_tests/test_freevc.py +++ b/tests/vc_tests/test_freevc.py @@ -55,7 +55,7 @@ def _test_forward(self, batch_size): config = FreeVCConfig() model = FreeVC(config).to(device) model.train() - print(" > Num parameters for FreeVC model:%s" % (count_parameters(model))) + print(f" > Num parameters for FreeVC model:{count_parameters(model)}") mel, spec, spec_lengths, waveform = self._create_inputs(config, batch_size)