Esempio n. 1
0
def preprocess_acoustic_model(exp: experiment.Experiment, args):
    """ Preprocesses data given in args using the experiment
        stored in exp. """
    #_get_raw(exp, args)
    logger.info("Loading feature model wrapper %s for preprocessing" %
                (exp.config["acoustic_model"]))
    wrappers.load(exp.config["acoustic_model"]).preprocess(exp, vars(args))
    logger.info("Preprocessing done")
Esempio n. 2
0
def synthesize(exp: experiment.Experiment, args) -> None:
    """ Synthesizes inside an experiment folder. """
    sentences = _get_sentences(args)
    logger.info("Loading acoustic feature model wrapper %s for synthesis" %
                (exp.config["acoustic_model"]))
    acoustic_module_wrapper = wrappers.load(exp.config["acoustic_model"])
    acoustic_module_wrapper.generate(exp,
                                     sentences,
                                     generate_features=args.use_wavegen,
                                     generate_waveforms=(not args.use_wavegen))
    logger.info("Synthesis from acoustic feature model done")

    if args.use_wavegen:
        wavegen_module_wrapper = wrappers.load(exp.config["wavegen_model"])
        wavegen_module_wrapper.generate(exp)
Esempio n. 3
0
def train(exp: experiment.Experiment, args) -> None:
    """ Trains acoustic feature prediction and waveform generation models. """
    # TODO: pause/resume training
    if args.model in ("acoustic", "both"):
        logger.info("Loading acoustic feature model wrapper %s for training" %
                    (exp.config["acoustic_model"]))
        module_wrapper = wrappers.load(exp.config["acoustic_model"])
        module_wrapper.train(exp, vars(args))
        logger.info("Training acoustic feature model done")
        # TODO: generate intermediate features if successful

    if args.model in ("wavegen", "both") and exp.config["wavegen_model"]:
        # TODO: check if intermediate features exist
        logger.info("Loading waveform generation model wrapper %s for training" %
                    (exp.config["wavegen_model"]))
        module_wrapper = wrappers.load(exp.config["wavegen_model"])
        module_wrapper.train(exp, vars(args))
Esempio n. 4
0
def create_wavegen_model(exp: experiment.Experiment, args):
    """ Loads and creates the wavegen model. """
    module_wrapper = wrappers.load(exp.config["wavegen_model"])
    module_wrapper.create(exp, vars(args))
    if args.download_wavegen_model:
        logger.info("Downloading wavegen model %s for model type %s" %
                    (args.download_wavegen_model, args.wavegen_model))
        module_wrapper.download_pretrained(
            exp, consts.PRETRAINED_WAVEGEN_MODELS[args.download_wavegen_model][
                args.wavegen_model])
Esempio n. 5
0
def create_acoustic_model(exp: experiment.Experiment, args):
    """ Loads and creates the acoustic model. """
    module_wrapper = wrappers.load(exp.config["acoustic_model"])
    module_wrapper.create(exp, vars(args))
    if args.download_acoustic_model:
        logger.info("Downloading acoustic model %s for model type %s" %
                    (args.download_acoustic_model, args.acoustic_model))
        module_wrapper.download_pretrained(
            exp, consts.PRETRAINED_ACOUSTIC_MODELS[
                args.download_acoustic_model][args.acoustic_model])
Esempio n. 6
0
def main():
    """ main function for creating a new experiment directory. """
    parser = argparse.ArgumentParser()
    parser.add_argument('experiment_dir',
                        help='Directory for the experiment to create.')
    parser.add_argument('--acoustic_model', default="tacotron2",
                        help='Model to use for acoustic feature prediction (tacotron2).')
    parser.add_argument('--download_acoustic_model', default=None,
                        choices=consts.PRETRAINED_FEATURE_MODELS.keys(),
                        help=('Name of a pretrained feature model to download (%s)'
                              % (" ".join(consts.PRETRAINED_FEATURE_MODELS.keys()))))
    parser.add_argument('--wavegen_model', default="none",
                        help='Model to use for waveform generation (wavernn or none). Default: none')
    parser.add_argument('--force', action='store_const', const=True,
                        help='Forces creation of this experiment, deleting an existing experiment if necessary')
    args = parser.parse_args()

    if os.path.exists(args.experiment_dir):
        if args.force:
            logger.info("Deleting existing experiment at %s" %
                        (args.experiment_dir))
            shutil.rmtree(args.experiment_dir)
        else:
            print("Experiment already exists at %s, stopping" %
                  (args.experiment_dir))
            return -1

    logger.info("Creating experiment at %s" % (args.experiment_dir))
    exp = experiment.create(args.experiment_dir, args)
    try:
        module_wrapper = wrappers.load(exp.config["acoustic_model"])
        module_wrapper.create(exp, vars(args))
        if args.download_acoustic_model:
            logger.info("Downloading feature model %s" %
                        (args.download_acoustic_model))
            module_wrapper.download_pretrained(
                exp, _get_download_url(consts.PRETRAINED_FEATURE_MODELS, args))
        experiment.save(exp)
    except ModuleNotFoundError as mnfe:
        print(mnfe)
        print("Module for %s not found, did you run install.sh?" %
              (args.acoustic_model))
    return 0