Changeset c81c3d2


Ignore:
Timestamp:
Sep 16, 2017, 4:42:20 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:
930bfec
Parents:
8dd5d40
Message:

python/lib/aubio/cut.py: use AubioArgumentParser?

File:
1 edited

Legend:

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

    r8dd5d40 rc81c3d2  
    66
    77import sys
    8 import argparse
     8from aubio.cmd import AubioArgumentParser
    99
    1010def aubio_cut_parser():
    11     parser = argparse.ArgumentParser()
    12     parser.add_argument("source_file", default=None, nargs='?',
    13             help="input sound file to analyse", metavar = "<source_file>")
    14     parser.add_argument("-i", "--input", action = "store", dest = "source_file2",
    15             help="input sound file to analyse", metavar = "<source_file>")
     11    parser = AubioArgumentParser()
     12    parser.add_input()
    1613    parser.add_argument("-O","--onset-method",
    1714            action="store", dest="onset_method", default='default',
     
    2219    parser.add_argument("-b","--beat",
    2320            action="store_true", dest="beat", default=False,
    24             help="use beat locations")
     21            help="slice at beat locations")
    2522    """
    2623    parser.add_argument("-S","--silencecut",
     
    3330            """
    3431    # algorithm parameters
    35     parser.add_argument("-r", "--samplerate",
    36             metavar = "<freq>", type=int,
    37             action="store", dest="samplerate", default=0,
    38             help="samplerate at which the file should be represented")
    39     parser.add_argument("-B","--bufsize",
    40             action="store", dest="bufsize", default=512,
    41             metavar = "<size>", type=int,
    42             help="buffer size [default=512]")
    43     parser.add_argument("-H","--hopsize",
    44             metavar = "<size>", type=int,
    45             action="store", dest="hopsize", default=256,
    46             help="overlap size [default=256]")
    47     parser.add_argument("-t","--onset-threshold",
    48             metavar = "<value>", type=float,
     32    parser.add_buf_hop_size()
     33    parser.add_argument("-t","--threshold", "--onset-threshold",
     34            metavar = "<threshold>", type=float,
    4935            action="store", dest="threshold", default=0.3,
    5036            help="onset peak picking threshold [default=0.3]")
    5137    parser.add_argument("-c","--cut",
    5238            action="store_true", dest="cut", default=False,
    53             help="cut input sound file at detected labels \
    54                     best used with option -L")
    55 
    56     # minioi
    57     parser.add_argument("-M","--minioi",
    58             metavar = "<value>", type=str,
    59             action="store", dest="minioi", default="12ms",
    60             help="minimum inter onset interval [default=12ms]")
     39            help="cut input sound file at detected labels")
     40    parser.add_minioi()
    6141
    6242    """
     
    8060            action="store", dest="zerothres", default=0.008,
    8161            help="zero-crossing threshold for slicing [default=0.00008]")
    82             """
    8362    # plotting functions
    84     """
    8563    parser.add_argument("-p","--plot",
    8664            action="store_true", dest="plot", default=False,
     
    10886            help="add spectrogram to the plot")
    10987    """
    110     parser.add_argument("-o","--output", type = str,
    111             metavar = "<outputdir>",
    112             action="store", dest="output_directory", default=None,
    113             help="specify path where slices of the original file should be created")
    114     parser.add_argument("--cut-until-nsamples", type = int,
    115             metavar = "<samples>",
    116             action = "store", dest = "cut_until_nsamples", default = None,
    117             help="how many extra samples should be added at the end of each slice")
    118     parser.add_argument("--cut-every-nslices", type = int,
    119             metavar = "<samples>",
    120             action = "store", dest = "cut_every_nslices", default = None,
    121             help="how many slices should be groupped together at each cut")
    122     parser.add_argument("--cut-until-nslices", type = int,
    123             metavar = "<slices>",
    124             action = "store", dest = "cut_until_nslices", default = None,
    125             help="how many extra slices should be added at the end of each slice")
    126 
    127     parser.add_argument("-v","--verbose",
    128             action="store_true", dest="verbose", default=True,
    129             help="make lots of noise [default]")
    130     parser.add_argument("-q","--quiet",
    131             action="store_false", dest="verbose", default=True,
    132             help="be quiet")
     88    parser.add_slicer_options()
     89    parser.add_verbose_help()
    13390    return parser
    13491
    13592
    13693def _cut_analyze(options):
    137     source_file = options.source_file
    138     hopsize = options.hopsize
    139     bufsize = options.bufsize
     94    hopsize = options.hop_size
     95    bufsize = options.buf_size
    14096    samplerate = options.samplerate
    141     source_file = options.source_file
     97    source_uri = options.source_uri
    14298
    14399    # analyze pass
    144100    from aubio import onset, tempo, source
    145101
    146     s = source(source_file, samplerate, hopsize)
     102    s = source(source_uri, samplerate, hopsize)
    147103    if samplerate == 0:
    148104        samplerate = s.get_samplerate()
     
    192148            timestamps_end = [t for t in timestamps[1 + options.cut_until_nslices:]]
    193149            timestamps_end += [ 1e120 ] * (options.cut_until_nslices + 1)
    194         slice_source_at_stamps(options.source_file,
     150        slice_source_at_stamps(options.source_uri,
    195151                timestamps, timestamps_end = timestamps_end,
    196152                output_dir = options.output_directory,
     
    200156    parser = aubio_cut_parser()
    201157    options = parser.parse_args()
    202     if not options.source_file and not options.source_file2:
     158    if not options.source_uri and not options.source_uri2:
    203159        sys.stderr.write("Error: no file name given\n")
    204160        parser.print_help()
    205161        sys.exit(1)
    206     elif options.source_file2 is not None:
    207         options.source_file = options.source_file2
     162    elif options.source_uri2 is not None:
     163        options.source_uri = options.source_uri2
    208164
    209165    # analysis
     
    212168    # print some info
    213169    duration = float (total_frames) / float(options.samplerate)
    214     base_info = '%(source_file)s' % {'source_file': options.source_file}
     170    base_info = '%(source_uri)s' % {'source_uri': options.source_uri}
    215171    base_info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % \
    216172            {'duration': duration, 'samplerate': options.samplerate}
Note: See TracChangeset for help on using the changeset viewer.