History

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

Paul Brossier committed 9 years ago

Commit 8dd5d401 parent eb8f7d51 file · +58 −0Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/lib/aubio/cmd.py+58−0
@@ -33,6 +33,7 @@ def aubio_parser(): · 32 unmodified lines
3333 parser_add_subcommand_mfcc(subparsers)
3434 parser_add_subcommand_melbands(subparsers)
3535 parser_add_subcommand_quiet(subparsers)
36+ parser_add_subcommand_cut(subparsers)
3637
3738 return parser
3839
@@ -135,6 +136,23 @@ def parser_add_subcommand_quiet(subparsers): · 96 unmodified lines
135136 subparser.add_verbose_help()
136137 subparser.set_defaults(process=process_quiet)
137138
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+
138156 class AubioArgumentParser(argparse.ArgumentParser):
139157
140158 def add_input(self):
@@ -212,6 +230,24 @@ class AubioArgumentParser(argparse.ArgumentParser): · 71 unmodified lines
212230 default=None,
213231 help=helpstr)
214232
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+
215251 # some utilities
216252
217253 def samples2seconds(n_frames, samplerate):
@@ -439,6 +475,28 @@ class process_quiet(default_process): · 221 unmodified lines
439475 fmt_out += self.time2string(frames_read, samplerate)
440476 sys.stdout.write(fmt_out + '\n')
441477
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+
442500 def main():
443501 parser = aubio_parser()
444502 args = parser.parse_args()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t