コード例 #1
0
import json
import os
import pickle

import numpy as np
from tqdm import tqdm
from joblib import Parallel, delayed

import argutils
from mano_train.options import expopts, simulopts
from mano_train.netscripts import savemano, simulate
from mano_train.objectutils.objectio import load_obj


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Simulation')
    expopts.add_exp_opts(parser)
    simulopts.add_simul_opts(parser)
    args = parser.parse_args()
    argutils.print_args(args)
    simulate.full_simul(
        exp_id=args.exp_id,
        batch_step=args.batch_step,
        wait_time=args.wait_time,
        sample_vis_freq=args.sample_vis_freq,
        use_gui=args.use_gui,
        sample_step=args.sample_step,
        workers=args.workers,
        cluster=args.cluster)
    print('All done!')
コード例 #2
0
ファイル: demo_toolbox.py プロジェクト: nam1665/voice_clone
def excepthook(exc_type, exc_value, exc_tb):
    traceback.print_exception(exc_type, exc_value, exc_tb)
    sys.exit(1)

if __name__ == '__main__':
    sys.excepthook = excepthook

    parser = argparse.ArgumentParser(
        description="Runs the toolbox",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )
    
    parser.add_argument("datasets_root", type=Path, help= \
        "Path to the directory containing your datasets. See toolbox/__init__.py for a list of "
        "supported datasets. You can add your own data by created a directory named UserAudio "
        "in your datasets root. Supported formats are mp3, flac, wav and m4a. Each speaker should "
        "be inside a directory, e.g. <datasets_root>/UserAudio/speaker_01/audio_01.wav.")
    parser.add_argument("-e", "--enc_models_dir", type=Path, default="encoder/saved_models", 
                        help="Directory containing saved encoder models")
    parser.add_argument("-s", "--syn_models_dir", type=Path, default="synthesizer/saved_models", 
                        help="Directory containing saved synthesizer models")
    parser.add_argument("-v", "--voc_models_dir", type=Path, default="vocoder/saved_models", 
                        help="Directory containing saved vocoder models")
    args = parser.parse_args()

    # Launch the toolbox
    print_args(args, parser)
    Toolbox(**vars(args))
    
コード例 #3
0
def go(args):
    print('args', args)
    method = 'sub' if args.subtitles else 'sil'
    input_parent = args.i.parent
    filename = '.'.join(args.i.name.split('.')[:-1])
    args.out_fmt = args.out_fmt or args.i.name.split('.')[-1]

    if args.subtitles and args.subtitles.exists():
        if args.force or input(
                f'WARNING: passed subtitle file does not exist "{args.subtitles}"'
                f'split with silences? [yes/(N)o]').lower() in ['y', 'yes']:
            args.subtitles = None
        else:
            print('exiting')
            return 1

    print('variables:', {
        '{INPUT}': input_parent,
        '{NAME}': filename,
        '{METHOD}': method
    })

    args.o = Path(args.o.as_posix().format(
        INPUT=input_parent,
        NAME=filename,
        METHOD=method,
    )).joinpath(filename)

    try:
        # noinspection PyUnresolvedReferences
        from argutils import print_args

        print_args(args)
    except:
        pass

    # if output already exists, check user or check if forced
    existing_files = list(args.o.glob('*[!.meta.json]'))
    if not args.child and args.o.is_dir() and existing_files:
        print(
            f'{args.o} already exists and is nonempty, choose the "--force" option to overwrite it.'
        )
        if (args.force or input(f'overwrite "{args.o}"? [yes/(N)o]').lower()
                in ['y', 'yes']):
            print('DELETING', args.o)
            list(map(os.remove, existing_files))
        else:
            print('exiting')
            return 1
    else:
        args.o.mkdir(parents=True, exist_ok=True)

    args.input = args.i
    args.out = args.o
    # check samplerate
    try:
        if args.samplerate > 0:
            _check_samplerate(args)
        else:
            print("Skipping samplerate check.")
    except Exception as e:
        print('Warning: Could not check sample using ffmpeg', e)
    # take action
    if args.subtitles:
        print(f'splicing "{args.i}" using subtitles')
        splice_using_subtitles(**vars(args))
    else:
        print(f'splicing "{args.i}" using silences. You can use --subtitles')
        splice_using_silences(**vars(args))

    print('saved to output directory:', args.o)
    return 0
コード例 #4
0
def main():
    try:
        import gooey
    except ImportError:
        gooey = None
        print("INFO: Failed to import Gooey (GUI disabled)")

    def flex_add_argument(f):
        """Make the add_argument accept (and ignore) the widget option."""
        def f_decorated(*args, **kwargs):
            kwargs.pop('widget', None)
            kwargs.pop('gooey_options', None)
            return f(*args, **kwargs)

        return f_decorated

    # Monkey-patching a private class…
    argparse._ActionsContainer.add_argument = flex_add_argument(
        argparse.ArgumentParser.add_argument)

    # Do not run GUI if it is not available or if command-line arguments are given.
    if gooey is None or len(sys.argv) > 1:
        ArgumentParser = argparse.ArgumentParser

        def gui_decorator(f):
            return f
    else:
        print('Using Gooey')
        ArgumentParser = gooey.GooeyParser
        gui_decorator = gooey.Gooey(
            program_name='Audio splicer',
            progress_regex=r"(\d+)%",
            navigation='TABBED',
            suppress_gooey_flag=True,
        )
        # in gooey mode, --force is always set
        sys.argv.append('--force')

    @gui_decorator
    def get_parser():
        parser = ArgumentParser(
            description=
            'Given a single sound file, tries to split it to segments.'
            'This is a preprocessing step for speech datasets (specifically LibriSpeech).'
            'It can split on silences or using a subtitles file. And will generate a ".trans.txt" file.'
            'Gooey GUI is used if it is installed and no arguments are passed.',
            formatter_class=argparse.ArgumentDefaultsHelpFormatter)

        parser.add_argument('-i',
                            metavar='INPUT_AUDIO',
                            type=Path,
                            widget='FileChooser',
                            nargs='+',
                            gooey_options={
                                'validator': {
                                    'test': 'user_input != None',
                                    'message': 'Choose a valid file path'
                                }
                            },
                            help='audio file input path')
        parser.add_argument(
            '-o',
            metavar='OUT_FOLDER',
            type=Path,
            widget='DirChooser',
            default='{INPUT}/splits-{METHOD}',
            gooey_options={
                'validator': {
                    'test': 'user_input != None',
                    'message': 'Choose a valid directory path'
                }
            },
            help='output directory path. '
            '{INPUT} means the input directory. '
            '{METHOD} means "sil" (silences), or "sub" (subtitles)')
        parser.add_argument(
            '--n_procs',
            default=cpu_count(),
            type=int,
            help='Multiprocessing concurrency level (best to leave at default).'
        )
        parser.add_argument(
            '--samplerate',
            default=0,
            type=int,
            help=
            'Assert target samplerate. If 0 then any samplerate is allowed.')
        # the action: either split based on .rst file, or split based on audio only
        group_subtitles = parser.add_argument_group('Subtitles')
        # read .rst file
        group_subtitles.add_argument(
            '-b',
            '--subtitles',
            metavar='SUBTITLES_FILE',
            type=Path,
            widget='FileChooser',
            gooey_options={
                'validator': {
                    'test': 'user_input != None',
                    'message': 'Choose a valid path'
                }
            },
            help=
            'split audio based on subtitle times from the passed .rst/.ass file'
            'If not passed, will split words based on silences. '
            'Can specify --min_silence_len and --silence_thresh')
        group_subtitles.add_argument(
            '--subtitle_end_offset',
            default=100,
            type=int,
            help='add delay at end of subtitle dialogue (milliseconds). '
            'If the audio segments say more than the text, then make this smaller. '
        )

        group_subtitles.add_argument(
            '--subtitle_rescale',
            default=1.0,
            type=float,
            help='rescale the timings if the audio was rescaled (stretched).'
            'Example1: If subtitle_rescale=2, then it will finish in half the original time.'
            'Example2: If the subtitle dialogues are ahead (appear earlier) of the audio, increase subtitle_rescale.'
        )

        group_silences = parser.add_argument_group('Silences')
        group_silences.add_argument(
            '-sl',
            '--min_silence_len',
            default=700,
            type=int,
            help=
            'must be silent for at least MIN_SILENCE_LEN (ms) to count as a silence. '
        )
        group_silences.add_argument(
            '-st',
            '--silence_thresh',
            default=-50,
            type=float,
            help='consider it silent if quieter than SILENCE_THRESH dBFS. ')

        parser.add_argument('--min_len',
                            default=6000,
                            type=int,
                            help='minimum length for each segment in ms. ')
        parser.add_argument('--max_len',
                            default=13000,
                            type=int,
                            help='maximum length for each segment in ms. ')

        parser.add_argument(
            '--out_fmt',
            metavar='FILE_EXT',
            default='',
            help=
            'output file extension {"", mp3, wav, flac, ...}. Empty means same as input'
        )

        parser.add_argument('-f',
                            '--force',
                            action='store_true',
                            help='Overwrite if output already exists')
        return parser

    parser = get_parser()

    try:
        import argcomplete
        argcomplete.autocomplete(parser)
    except:
        print("INFO: failed to import `argcomplete` lib")

    args = parser.parse_args(sys.argv[1:])

    # expand directory
    input_dir = args.i[0]
    if len(args.i) == 1 and input_dir.is_dir():
        args.i = list(input_dir.rglob('*.mp3'))
        assert len(args.i) > 0, 'No mp3 files found in input directory:'
        print('input is a folder, found mp3 files:', args.i)

    try:
        # noinspection PyUnresolvedReferences
        from argutils import print_args

        print_args(args)
    except:
        pass

    # make args for each input file
    args_list = []
    for i in args.i:
        args_clone = deepcopy(args)
        args_clone.i = i
        args_clone.child = len(args.i) > 1
        args_list.append(args_clone)

    n_procs = args.n_procs
    ret_codes = list(Pool(n_procs).map(go, args_list))

    return max(ret_codes)
コード例 #5
0
    parser.add_argument('--score_iter',
                        type=int,
                        default=10,
                        help='What itertation use to average results')
    parser.add_argument(
        '--prefixes',
        nargs='+',
        type=str,
        help='Descriptions of run for labels, one per checkpoint')
    parser.add_argument('--valid', action='store_true')
    parser.add_argument('--aggreg', action='store_true')
    parser.add_argument('--train', action='store_true')
    parser.add_argument('--lr', action='store_true')
    parser.add_argument('--gteagazeplus', action='store_true')
    opt = parser.parse_args()
    argutils.print_args(opt)

    if opt.prefixes is not None:
        assert len(opt.prefixes) == len(opt.checkpoints), \
            'Should have as many prefixes as checkpoints but '\
            'got {} and {}'.format(opt.prefixes, opt.checkpoints)

    if opt.gteagazeplus:
        template_aggreg = os.path.join(opt.checkpoint,
                                       'gtea_lo_{}/valid_aggreg.txt')
        template_valid = os.path.join(opt.checkpoint,
                                      'gtea_lo_{}/valid_log.txt')
        template_train = os.path.join(opt.checkpoint,
                                      'gtea_lo_{}/train_log.txt')

        if opt.aggreg: