switching to high quality piper tts and added label translations
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Training code for Piper 1."""
|
||||
@@ -0,0 +1,38 @@
|
||||
import logging
|
||||
|
||||
import torch
|
||||
from lightning.pytorch.cli import LightningCLI
|
||||
|
||||
from .vits.dataset import VitsDataModule
|
||||
from .vits.lightning import VitsModel
|
||||
|
||||
_LOGGER = logging.getLogger(__package__)
|
||||
|
||||
|
||||
class VitsLightningCLI(LightningCLI):
|
||||
def add_arguments_to_parser(self, parser):
|
||||
parser.link_arguments("data.batch_size", "model.batch_size")
|
||||
parser.link_arguments("data.num_symbols", "model.num_symbols")
|
||||
parser.link_arguments("model.num_speakers", "data.num_speakers")
|
||||
parser.link_arguments("model.sample_rate", "data.sample_rate")
|
||||
parser.link_arguments("model.filter_length", "data.filter_length")
|
||||
parser.link_arguments("model.hop_length", "data.hop_length")
|
||||
parser.link_arguments("model.win_length", "data.win_length")
|
||||
parser.link_arguments("model.segment_size", "data.segment_size")
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
torch.backends.cuda.matmul.allow_tf32 = True
|
||||
torch.backends.cudnn.allow_tf32 = True
|
||||
torch.backends.cudnn.deterministic = False
|
||||
_cli = VitsLightningCLI( # noqa: ignore=F841
|
||||
VitsModel, VitsDataModule, trainer_defaults={"max_epochs": -1}
|
||||
)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
import torch
|
||||
|
||||
from .vits.lightning import VitsModel
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Main entry point"""
|
||||
torch.manual_seed(1234)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--checkpoint", required=True, help="Path to model checkpoint (.ckpt)"
|
||||
)
|
||||
parser.add_argument("--generator", required=True, help="Path to output file (.pt)")
|
||||
|
||||
parser.add_argument(
|
||||
"--debug", action="store_true", help="Print DEBUG messages to the console"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
else:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
_LOGGER.debug(args)
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
generator_path = Path(args.generator)
|
||||
generator_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
checkpoint_path = Path(args.checkpoint)
|
||||
|
||||
# pylint: disable=no-value-for-parameter
|
||||
model = VitsModel.load_from_checkpoint(checkpoint_path, map_location="cpu")
|
||||
model_g = model.model_g
|
||||
|
||||
# Inference only
|
||||
model_g.eval()
|
||||
|
||||
with torch.no_grad():
|
||||
model_g.dec.remove_weight_norm()
|
||||
|
||||
model_g.forward = model_g.infer # type: ignore[method-assign,assignment]
|
||||
|
||||
torch.save(model_g, generator_path)
|
||||
_LOGGER.info("Exported generator to %s", generator_path)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import torch
|
||||
|
||||
from .vits.lightning import VitsModel
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
OPSET_VERSION = 15
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Main entry point"""
|
||||
torch.manual_seed(1234)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--checkpoint", required=True, help="Path to model checkpoint (.ckpt)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output-file", required=True, help="Path to output file (.onnx)"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--debug", action="store_true", help="Print DEBUG messages to the console"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
else:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
_LOGGER.debug(args)
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
|
||||
output_path = Path(args.output_file)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
checkpoint_path = Path(args.checkpoint)
|
||||
|
||||
# pylint: disable=no-value-for-parameter
|
||||
model = VitsModel.load_from_checkpoint(checkpoint_path, map_location="cpu")
|
||||
model_g = model.model_g
|
||||
|
||||
# Inference only
|
||||
model_g.eval()
|
||||
|
||||
with torch.no_grad():
|
||||
model_g.dec.remove_weight_norm()
|
||||
|
||||
def infer_forward(text, text_lengths, scales, sid=None):
|
||||
noise_scale = scales[0]
|
||||
length_scale = scales[1]
|
||||
noise_scale_w = scales[2]
|
||||
audio = model_g.infer(
|
||||
text,
|
||||
text_lengths,
|
||||
noise_scale=noise_scale,
|
||||
length_scale=length_scale,
|
||||
noise_scale_w=noise_scale_w,
|
||||
sid=sid,
|
||||
)[0].unsqueeze(1)
|
||||
|
||||
return audio
|
||||
|
||||
model_g.forward = infer_forward # type: ignore[method-assign,assignment]
|
||||
|
||||
num_symbols = model_g.n_vocab
|
||||
num_speakers = model_g.n_speakers
|
||||
|
||||
dummy_input_length = 50
|
||||
sequences = torch.randint(
|
||||
low=0, high=num_symbols, size=(1, dummy_input_length), dtype=torch.long
|
||||
)
|
||||
sequence_lengths = torch.LongTensor([sequences.size(1)])
|
||||
|
||||
sid: Optional[torch.LongTensor] = None
|
||||
if num_speakers > 1:
|
||||
sid = torch.LongTensor([0])
|
||||
|
||||
# noise, noise_w, length
|
||||
scales = torch.FloatTensor([0.667, 1.0, 0.8])
|
||||
dummy_input = (sequences, sequence_lengths, scales, sid)
|
||||
|
||||
# Export
|
||||
torch.onnx.export(
|
||||
model=model_g,
|
||||
args=dummy_input,
|
||||
f=output_path,
|
||||
verbose=False,
|
||||
opset_version=OPSET_VERSION,
|
||||
input_names=["input", "input_lengths", "scales", "sid"],
|
||||
output_names=["output"],
|
||||
dynamic_axes={
|
||||
"input": {0: "batch_size", 1: "phonemes"},
|
||||
"input_lengths": {0: "batch_size"},
|
||||
"output": {0: "batch_size", 2: "time"},
|
||||
},
|
||||
)
|
||||
_LOGGER.info("Exported model to %s", output_path)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user