Changeset a5004903
- Timestamp:
- Apr 16, 2017, 11:38:10 AM (8 years ago)
- 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:
- 9956027
- Parents:
- 2bf530e0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/cut.py
r2bf530e0 ra5004903 6 6 7 7 import sys 8 import argparse 8 9 9 10 def parse_args(): 10 from optparse import OptionParser11 11 usage = "usage: %s [options] -i soundfile" % sys.argv[0] 12 12 usage += "\n help: %s -h" % sys.argv[0] 13 parser = OptionParser(usage=usage)14 parser.add_ option("-i", "--input", action = "store", dest = "source_file",13 parser = argparse.ArgumentParser() 14 parser.add_argument("source_file", default=None, nargs='?', 15 15 help="input sound file to analyse", metavar = "<source_file>") 16 parser.add_option("-O","--onset-method", 16 parser.add_argument("-i", "--input", action = "store", dest = "source_file2", 17 help="input sound file to analyse", metavar = "<source_file>") 18 parser.add_argument("-O","--onset-method", 17 19 action="store", dest="onset_method", default='default', 18 20 metavar = "<onset_method>", … … 20 22 complexdomain|hfc|phase|specdiff|energy|kl|mkl") 21 23 # cutting methods 22 parser.add_ option("-b","--beat",24 parser.add_argument("-b","--beat", 23 25 action="store_true", dest="beat", default=False, 24 26 help="use beat locations") 25 27 """ 26 parser.add_ option("-S","--silencecut",28 parser.add_argument("-S","--silencecut", 27 29 action="store_true", dest="silencecut", default=False, 28 30 help="use silence locations") 29 parser.add_ option("-s","--silence",31 parser.add_argument("-s","--silence", 30 32 metavar = "<value>", 31 33 action="store", dest="silence", default=-70, … … 33 35 """ 34 36 # algorithm parameters 35 parser.add_ option("-r", "--samplerate",36 metavar = "<freq>", type= 'int',37 parser.add_argument("-r", "--samplerate", 38 metavar = "<freq>", type=int, 37 39 action="store", dest="samplerate", default=0, 38 40 help="samplerate at which the file should be represented") 39 parser.add_ option("-B","--bufsize",41 parser.add_argument("-B","--bufsize", 40 42 action="store", dest="bufsize", default=512, 41 metavar = "<size>", type= 'int',43 metavar = "<size>", type=int, 42 44 help="buffer size [default=512]") 43 parser.add_ option("-H","--hopsize",44 metavar = "<size>", type= 'int',45 parser.add_argument("-H","--hopsize", 46 metavar = "<size>", type=int, 45 47 action="store", dest="hopsize", default=256, 46 48 help="overlap size [default=256]") 47 parser.add_ option("-t","--onset-threshold",48 metavar = "<value>", type= "float",49 parser.add_argument("-t","--onset-threshold", 50 metavar = "<value>", type=float, 49 51 action="store", dest="threshold", default=0.3, 50 52 help="onset peak picking threshold [default=0.3]") 51 parser.add_ option("-c","--cut",53 parser.add_argument("-c","--cut", 52 54 action="store_true", dest="cut", default=False, 53 55 help="cut input sound file at detected labels \ … … 55 57 56 58 # minioi 57 parser.add_ option("-M","--minioi",58 metavar = "<value>", type= 'string',59 parser.add_argument("-M","--minioi", 60 metavar = "<value>", type=str, 59 61 action="store", dest="minioi", default="12ms", 60 62 help="minimum inter onset interval [default=12ms]") 61 63 62 64 """ 63 parser.add_ option("-D","--delay",64 action = "store", dest = "delay", type = "float",65 parser.add_argument("-D","--delay", 66 action = "store", dest = "delay", type = float, 65 67 metavar = "<seconds>", default=0, 66 68 help="number of seconds to take back [default=system]\ 67 69 default system delay is 3*hopsize/samplerate") 68 parser.add_ option("-C","--dcthreshold",70 parser.add_argument("-C","--dcthreshold", 69 71 metavar = "<value>", 70 72 action="store", dest="dcthreshold", default=1., 71 73 help="onset peak picking DC component [default=1.]") 72 parser.add_ option("-L","--localmin",74 parser.add_argument("-L","--localmin", 73 75 action="store_true", dest="localmin", default=False, 74 76 help="use local minima after peak detection") 75 parser.add_ option("-d","--derivate",77 parser.add_argument("-d","--derivate", 76 78 action="store_true", dest="derivate", default=False, 77 79 help="derivate onset detection function") 78 parser.add_ option("-z","--zerocross",80 parser.add_argument("-z","--zerocross", 79 81 metavar = "<value>", 80 82 action="store", dest="zerothres", default=0.008, … … 83 85 # plotting functions 84 86 """ 85 parser.add_ option("-p","--plot",87 parser.add_argument("-p","--plot", 86 88 action="store_true", dest="plot", default=False, 87 89 help="draw plot") 88 parser.add_ option("-x","--xsize",90 parser.add_argument("-x","--xsize", 89 91 metavar = "<size>", 90 92 action="store", dest="xsize", default=1., 91 type= 'float', help="define xsize for plot")92 parser.add_ option("-y","--ysize",93 type=float, help="define xsize for plot") 94 parser.add_argument("-y","--ysize", 93 95 metavar = "<size>", 94 96 action="store", dest="ysize", default=1., 95 type= 'float', help="define ysize for plot")96 parser.add_ option("-f","--function",97 type=float, help="define ysize for plot") 98 parser.add_argument("-f","--function", 97 99 action="store_true", dest="func", default=False, 98 100 help="print detection function") 99 parser.add_ option("-n","--no-onsets",101 parser.add_argument("-n","--no-onsets", 100 102 action="store_true", dest="nplot", default=False, 101 103 help="do not plot detected onsets") 102 parser.add_ option("-O","--outplot",104 parser.add_argument("-O","--outplot", 103 105 metavar = "<output_image>", 104 106 action="store", dest="outplot", default=None, 105 107 help="save plot to output.{ps,png}") 106 parser.add_ option("-F","--spectrogram",108 parser.add_argument("-F","--spectrogram", 107 109 action="store_true", dest="spectro", default=False, 108 110 help="add spectrogram to the plot") 109 111 """ 110 parser.add_ option("-o","--output", type = str,112 parser.add_argument("-o","--output", type = str, 111 113 metavar = "<outputdir>", 112 114 action="store", dest="output_directory", default=None, 113 115 help="specify path where slices of the original file should be created") 114 parser.add_ option("--cut-until-nsamples", type = int,116 parser.add_argument("--cut-until-nsamples", type = int, 115 117 metavar = "<samples>", 116 118 action = "store", dest = "cut_until_nsamples", default = None, 117 119 help="how many extra samples should be added at the end of each slice") 118 parser.add_ option("--cut-every-nslices", type = int,120 parser.add_argument("--cut-every-nslices", type = int, 119 121 metavar = "<samples>", 120 122 action = "store", dest = "cut_every_nslices", default = None, 121 123 help="how many slices should be groupped together at each cut") 122 parser.add_ option("--cut-until-nslices", type = int,124 parser.add_argument("--cut-until-nslices", type = int, 123 125 metavar = "<slices>", 124 126 action = "store", dest = "cut_until_nslices", default = None, 125 127 help="how many extra slices should be added at the end of each slice") 126 128 127 parser.add_ option("-v","--verbose",129 parser.add_argument("-v","--verbose", 128 130 action="store_true", dest="verbose", default=True, 129 131 help="make lots of noise [default]") 130 parser.add_ option("-q","--quiet",132 parser.add_argument("-q","--quiet", 131 133 action="store_false", dest="verbose", default=True, 132 134 help="be quiet") 133 (options, args)= parser.parse_args()134 if not options.source_file:135 if len(args) == 1:136 options.source_file = args[0]137 else:138 print ("no file name given\n" + usage)139 sys.exit(1)140 return options,args135 args = parser.parse_args() 136 if not args.source_file and not args.source_file2: 137 sys.stderr.write("Error: no file name given\n") 138 parser.print_help() 139 sys.exit(1) 140 elif args.source_file2 is not None: 141 args.source_file = args.source_file2 142 return args 141 143 142 144 def main(): 143 options, args = parse_args() 144 145 options = parse_args() 146 147 source_file = options.source_file 145 148 hopsize = options.hopsize 146 149 bufsize = options.bufsize
Note: See TracChangeset
for help on using the changeset viewer.