Changeset c81c3d2
- Timestamp:
- Sep 16, 2017, 4:42:20 PM (7 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:
- 930bfec
- Parents:
- 8dd5d40
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/cut.py
r8dd5d40 rc81c3d2 6 6 7 7 import sys 8 import argparse 8 from aubio.cmd import AubioArgumentParser 9 9 10 10 def 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() 16 13 parser.add_argument("-O","--onset-method", 17 14 action="store", dest="onset_method", default='default', … … 22 19 parser.add_argument("-b","--beat", 23 20 action="store_true", dest="beat", default=False, 24 help=" usebeat locations")21 help="slice at beat locations") 25 22 """ 26 23 parser.add_argument("-S","--silencecut", … … 33 30 """ 34 31 # 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, 49 35 action="store", dest="threshold", default=0.3, 50 36 help="onset peak picking threshold [default=0.3]") 51 37 parser.add_argument("-c","--cut", 52 38 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() 61 41 62 42 """ … … 80 60 action="store", dest="zerothres", default=0.008, 81 61 help="zero-crossing threshold for slicing [default=0.00008]") 82 """83 62 # plotting functions 84 """85 63 parser.add_argument("-p","--plot", 86 64 action="store_true", dest="plot", default=False, … … 108 86 help="add spectrogram to the plot") 109 87 """ 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() 133 90 return parser 134 91 135 92 136 93 def _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 140 96 samplerate = options.samplerate 141 source_ file = options.source_file97 source_uri = options.source_uri 142 98 143 99 # analyze pass 144 100 from aubio import onset, tempo, source 145 101 146 s = source(source_ file, samplerate, hopsize)102 s = source(source_uri, samplerate, hopsize) 147 103 if samplerate == 0: 148 104 samplerate = s.get_samplerate() … … 192 148 timestamps_end = [t for t in timestamps[1 + options.cut_until_nslices:]] 193 149 timestamps_end += [ 1e120 ] * (options.cut_until_nslices + 1) 194 slice_source_at_stamps(options.source_ file,150 slice_source_at_stamps(options.source_uri, 195 151 timestamps, timestamps_end = timestamps_end, 196 152 output_dir = options.output_directory, … … 200 156 parser = aubio_cut_parser() 201 157 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: 203 159 sys.stderr.write("Error: no file name given\n") 204 160 parser.print_help() 205 161 sys.exit(1) 206 elif options.source_ file2 is not None:207 options.source_ file = options.source_file2162 elif options.source_uri2 is not None: 163 options.source_uri = options.source_uri2 208 164 209 165 # analysis … … 212 168 # print some info 213 169 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} 215 171 base_info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % \ 216 172 {'duration': duration, 'samplerate': options.samplerate}
Note: See TracChangeset
for help on using the changeset viewer.