[aubio-user] Split audio clip using Aubio
Paul Brossier
piem at aubio.org
Wed Feb 13 18:21:03 CET 2013
Hi Malintha!
On 2/13/13 1:18 AM, Malintha Adikari wrote:
> Hi, I want to split my audio file in to 20 seconds segments. Can I
> employ aubio for that operation? Then how can I do it ?
I just pushed a little python example to do that. It's not perfect
though: to get the exact duration, only part of the samples should be
written when a boundary is found.
> * Are you going to apply GSOC 2013 for aubio project ?
Yeah, that would be great. Any specific project in mind? :-)
Cheers, Paul
Here is the content of demo_slicing.py:
--
#! /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 <inputfile> <duration>' % 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
--
>
> Thanks, Malintha Adikari
>
>
> _______________________________________________ aubio-user mailing
> list aubio-user at aubio.org
> https://lists.aubio.org/listinfo/aubio-user
>
More information about the aubio-user
mailing list