feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change
on this file since b583c099 was
c11c549,
checked in by Paul Brossier <piem@piem.org>, 12 years ago
|
demos/demo_slicing.py: add simple slicing example
|
-
Property mode set to
100755
|
File size:
989 bytes
|
Rev | Line | |
---|
[c11c549] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | import sys |
---|
| 4 | import os.path |
---|
| 5 | from aubio import source, sink |
---|
| 6 | |
---|
| 7 | if __name__ == '__main__': |
---|
| 8 | if len(sys.argv) < 3: |
---|
| 9 | print 'usage: %s <inputfile> <duration>' % sys.argv[0] |
---|
| 10 | sys.exit(1) |
---|
| 11 | source_file = sys.argv[1] |
---|
| 12 | duration = float(sys.argv[2]) |
---|
| 13 | sink_base, sink_ext = os.path.splitext(os.path.basename(source_file)) |
---|
| 14 | slice_n, total_frames, read = 1, 0, 256 |
---|
| 15 | f = source(source_file, 0, 256) |
---|
| 16 | g = sink(sink_base + '-%02d' % slice_n + sink_ext, f.samplerate) |
---|
| 17 | while read: |
---|
| 18 | vec, read = f() |
---|
| 19 | g(vec, read) |
---|
| 20 | total_frames += read |
---|
| 21 | if total_frames / float(f.samplerate) >= duration * slice_n: |
---|
| 22 | slice_n += 1 |
---|
| 23 | del g |
---|
| 24 | g = sink(sink_base + '-%02d' % slice_n + sink_ext, f.samplerate) |
---|
| 25 | total_duration = total_frames / float(f.samplerate) |
---|
| 26 | print 'created %(slice_n)d slices from %(source_file)s' % locals(), |
---|
| 27 | print ' (total duration %(total_duration).2fs)' % locals() |
---|
| 28 | del f, g |
---|
Note: See
TracBrowser
for help on using the repository browser.