Changeset 8dd5d40 for python/lib


Ignore:
Timestamp:
Sep 16, 2017, 4:41:04 PM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
Children:
c81c3d2
Parents:
eb8f7d5
Message:

python/lib/aubio/cmd.py: add basic cut command

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/lib/aubio/cmd.py

    reb8f7d5 r8dd5d40  
    3434    parser_add_subcommand_melbands(subparsers)
    3535    parser_add_subcommand_quiet(subparsers)
     36    parser_add_subcommand_cut(subparsers)
    3637
    3738    return parser
     
    135136    subparser.add_verbose_help()
    136137    subparser.set_defaults(process=process_quiet)
     138
     139def parser_add_subcommand_cut(subparsers):
     140    # quiet subcommand
     141    subparser = subparsers.add_parser('cut',
     142            help='slice at timestamps')
     143    subparser.add_input()
     144    helpstr = "onset novelty function"
     145    helpstr += " <default|energy|hfc|complex|phase|specdiff|kl|mkl|specflux>"
     146    subparser.add_method(helpstr=helpstr)
     147    subparser.add_buf_hop_size()
     148    #subparser.add_silence()
     149    subparser.add_threshold(default=0.3)
     150    subparser.add_minioi()
     151    subparser.add_slicer_options()
     152    #subparser.add_time_format()
     153    subparser.add_verbose_help()
     154    subparser.set_defaults(process=process_cut)
    137155
    138156class AubioArgumentParser(argparse.ArgumentParser):
     
    212230                 default=None,
    213231                 help=helpstr)
     232
     233    def add_slicer_options(self):
     234        self.add_argument("-o","--output", type = str,
     235                metavar = "<outputdir>",
     236                action="store", dest="output_directory", default=None,
     237                help="specify path where slices of the original file should be created")
     238        self.add_argument("--cut-until-nsamples", type = int,
     239                metavar = "<samples>",
     240                action = "store", dest = "cut_until_nsamples", default = None,
     241                help="how many extra samples should be added at the end of each slice")
     242        self.add_argument("--cut-every-nslices", type = int,
     243                metavar = "<samples>",
     244                action = "store", dest = "cut_every_nslices", default = None,
     245                help="how many slices should be groupped together at each cut")
     246        self.add_argument("--cut-until-nslices", type = int,
     247                metavar = "<slices>",
     248                action = "store", dest = "cut_until_nslices", default = None,
     249                help="how many extra slices should be added at the end of each slice")
    214250
    215251# some utilities
     
    439475            fmt_out += self.time2string(frames_read, samplerate)
    440476            sys.stdout.write(fmt_out + '\n')
     477
     478class process_cut(process_onset):
     479    def __init__(self, args):
     480        super(process_cut, self).__init__(args)
     481        self.slices = []
     482        self.options = args
     483
     484    def __call__(self, block):
     485        ret = super(process_cut, self).__call__(block)
     486        if ret: self.slices.append(self.onset.get_last())
     487        return ret
     488
     489    def flush(self, frames_read, samplerate):
     490        from aubio.cut2 import _cut_slice
     491        _cut_slice(self.options, self.slices)
     492        duration = float (frames_read) / float(samplerate)
     493        base_info = '%(source_file)s' % {'source_file': self.options.source_uri}
     494        base_info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % \
     495                {'duration': duration, 'samplerate': samplerate}
     496        info = "created %d slices from " % len(self.slices)
     497        info += base_info
     498        sys.stderr.write(info)
    441499
    442500def main():
Note: See TracChangeset for help on using the changeset viewer.