Exemple #1
0
def play_collection():
    augmentations = parse_augmentations(CLI_ARGS.augment)
    if any(not isinstance(a, SampleAugmentation) for a in augmentations):
        print("Warning: Some of the augmentations cannot be simulated by this command.")
    samples = get_samples_in_play_order()
    samples = apply_sample_augmentations(samples,
                                         audio_type=AUDIO_TYPE_PCM,
                                         augmentations=augmentations,
                                         process_ahead=0,
                                         clock=CLI_ARGS.clock)
    for sample in samples:
        if not CLI_ARGS.quiet:
            print('Sample "{}"'.format(sample.sample_id), file=sys.stderr)
            if isinstance(sample, LabeledSample):
                print('  "{}"'.format(sample.transcript), file=sys.stderr)
        if CLI_ARGS.pipe:
            sample.change_audio_type(AUDIO_TYPE_WAV)
            sys.stdout.buffer.write(sample.audio.getvalue())
            return
        wave_obj = simpleaudio.WaveObject(sample.audio,
                                          sample.audio_format.channels,
                                          sample.audio_format.width,
                                          sample.audio_format.rate)
        play_obj = wave_obj.play()
        play_obj.wait_done()
Exemple #2
0
def build_sdb():
    audio_type = AUDIO_TYPE_LOOKUP[CLI_ARGS.audio_type]
    augmentations = parse_augmentations(CLI_ARGS.augment)
    if any(not isinstance(a, SampleAugmentation) for a in augmentations):
        print(
            "Warning: Some of the augmentations cannot be applied by this command."
        )
    with DirectSDBWriter(CLI_ARGS.target,
                         audio_type=audio_type,
                         labeled=not CLI_ARGS.unlabeled) as sdb_writer:
        samples = samples_from_sources(CLI_ARGS.sources,
                                       labeled=not CLI_ARGS.unlabeled)
        num_samples = len(samples)
        if augmentations:
            samples = apply_sample_augmentations(samples,
                                                 audio_type=AUDIO_TYPE_PCM,
                                                 augmentations=augmentations)
        bar = progressbar.ProgressBar(max_value=num_samples,
                                      widgets=SIMPLE_BAR)
        for sample in bar(
                change_audio_types(samples,
                                   audio_type=audio_type,
                                   bitrate=CLI_ARGS.bitrate,
                                   processes=CLI_ARGS.workers)):
            sdb_writer.add(sample)
def build_data_set():
    audio_type = AUDIO_TYPE_LOOKUP[CLI_ARGS.audio_type]
    augmentations = parse_augmentations(CLI_ARGS.augment)
    if any(not isinstance(a, SampleAugmentation) for a in augmentations):
        print(
            'Warning: Some of the specified augmentations will not get applied, as this tool only supports '
            'overlay, codec, reverb, resample and volume.')
    extension = Path(CLI_ARGS.target).suffix.lower()
    labeled = not CLI_ARGS.unlabeled
    if extension == '.csv':
        writer = CSVWriter(CLI_ARGS.target,
                           absolute_paths=CLI_ARGS.absolute_paths,
                           labeled=labeled)
    elif extension == '.sdb':
        writer = DirectSDBWriter(CLI_ARGS.target,
                                 audio_type=audio_type,
                                 labeled=labeled)
    elif extension == '.tar':
        writer = TarWriter(CLI_ARGS.target,
                           labeled=labeled,
                           gz=False,
                           include=CLI_ARGS.include)
    elif extension == '.tgz' or CLI_ARGS.target.lower().endswith('.tar.gz'):
        writer = TarWriter(CLI_ARGS.target,
                           labeled=labeled,
                           gz=True,
                           include=CLI_ARGS.include)
    else:
        print(
            'Unknown extension of target file - has to be either .csv, .sdb, .tar, .tar.gz or .tgz'
        )
        sys.exit(1)
    with writer:
        samples = samples_from_sources(CLI_ARGS.sources,
                                       labeled=not CLI_ARGS.unlabeled)
        num_samples = len(samples)
        if augmentations:
            samples = apply_sample_augmentations(samples,
                                                 audio_type=AUDIO_TYPE_PCM,
                                                 augmentations=augmentations)
        bar = progressbar.ProgressBar(max_value=num_samples,
                                      widgets=SIMPLE_BAR)
        for sample in bar(
                change_audio_types(samples,
                                   audio_type=audio_type,
                                   bitrate=CLI_ARGS.bitrate,
                                   processes=CLI_ARGS.workers)):
            writer.add(sample)