Chris@56: '''A high-level interface to the vampyhost extension module, for quickly and easily running Vamp audio analysis plugins on audio files and buffers.''' Chris@56: Chris@56: import numpy Chris@56: Chris@95: def frames_from_array(arr, step_size, frame_size): Chris@95: """Generate a list of frames of size frame_size, extracted from the input array arr at step_size intervals""" Chris@56: # presumably such a function exists in many places, but I need practice Chris@84: assert(step_size > 0) Chris@56: if arr.ndim == 1: # turn 1d into 2d array with 1 channel Chris@56: arr = numpy.reshape(arr, (1, arr.shape[0])) Chris@56: assert(arr.ndim == 2) Chris@56: n = arr.shape[1] Chris@56: i = 0 Chris@56: while (i < n): Chris@95: frame = arr[:, i : i + frame_size] Chris@56: w = frame.shape[1] Chris@95: if (w < frame_size): Chris@95: pad = numpy.zeros((frame.shape[0], frame_size - w)) Chris@56: frame = numpy.concatenate((frame, pad), 1) Chris@56: yield frame Chris@84: i = i + step_size Chris@56: