From c11c54987acc684346784d426d78bb8c9275057d Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Wed, 13 Feb 2013 12:12:52 -0500 Subject: [PATCH] demos/demo_slicing.py: add simple slicing example --- python/demos/demo_slicing.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 python/demos/demo_slicing.py diff --git a/python/demos/demo_slicing.py b/python/demos/demo_slicing.py new file mode 100755 index 00000000..3f2e2d28 --- /dev/null +++ b/python/demos/demo_slicing.py @@ -0,0 +1,28 @@ +#! /usr/bin/env python + +import sys +import os.path +from aubio import source, sink + +if __name__ == '__main__': + if len(sys.argv) < 3: + print 'usage: %s ' % sys.argv[0] + sys.exit(1) + source_file = sys.argv[1] + duration = float(sys.argv[2]) + sink_base, sink_ext = os.path.splitext(os.path.basename(source_file)) + slice_n, total_frames, read = 1, 0, 256 + f = source(source_file, 0, 256) + g = sink(sink_base + '-%02d' % slice_n + sink_ext, f.samplerate) + while read: + vec, read = f() + g(vec, read) + total_frames += read + if total_frames / float(f.samplerate) >= duration * slice_n: + slice_n += 1 + del g + g = sink(sink_base + '-%02d' % slice_n + sink_ext, f.samplerate) + total_duration = total_frames / float(f.samplerate) + print 'created %(slice_n)d slices from %(source_file)s' % locals(), + print ' (total duration %(total_duration).2fs)' % locals() + del f, g -- 2.11.0