Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -33,6 +33,7 @@ def aubio_parser(): · 32 unmodified lines | ||
| 33 | 33 | parser_add_subcommand_mfcc(subparsers) |
| 34 | 34 | parser_add_subcommand_melbands(subparsers) |
| 35 | 35 | parser_add_subcommand_quiet(subparsers) |
| 36 | + parser_add_subcommand_cut(subparsers) | |
| 36 | 37 | |
| 37 | 38 | return parser |
| 38 | 39 | |
| @@ -135,6 +136,23 @@ def parser_add_subcommand_quiet(subparsers): · 96 unmodified lines | ||
| 135 | 136 | subparser.add_verbose_help() |
| 136 | 137 | subparser.set_defaults(process=process_quiet) |
| 137 | 138 | |
| 139 | +def 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) | |
| 155 | + | |
| 138 | 156 | class AubioArgumentParser(argparse.ArgumentParser): |
| 139 | 157 | |
| 140 | 158 | def add_input(self): |
| @@ -212,6 +230,24 @@ class AubioArgumentParser(argparse.ArgumentParser): · 71 unmodified lines | ||
| 212 | 230 | default=None, |
| 213 | 231 | help=helpstr) |
| 214 | 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") | |
| 250 | + | |
| 215 | 251 | # some utilities |
| 216 | 252 | |
| 217 | 253 | def samples2seconds(n_frames, samplerate): |
| @@ -439,6 +475,28 @@ class process_quiet(default_process): · 221 unmodified lines | ||
| 439 | 475 | fmt_out += self.time2string(frames_read, samplerate) |
| 440 | 476 | sys.stdout.write(fmt_out + '\n') |
| 441 | 477 | |
| 478 | +class 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) | |
| 499 | + | |
| 442 | 500 | def main(): |
| 443 | 501 | parser = aubio_parser() |
| 444 | 502 | args = parser.parse_args() |