tools/utilities/pythonlibs/audio/training/make_dataset.py
def sliding_window_frame(source, window_size, shift_amount):
    """ General windowing and merging generator that concatenates & shifts samples through a sliding window frame """
    # Source is a container or generator that returns numpy vectors
    # We buffer them and return arrays of length window_size, shifted by shift_amount 
    buffer = None
    for new_samples in source:
        # if new_samples is a scalar, turn it into a 1-element tuple    
        if np.isscalar(new_samples):
            new_samples = (new_samples,)
        if buffer is None:
            buffer = new_samples
        else:
            buffer = np.concatenate((buffer, new_samples))

        while len(buffer) >= window_size:
            yield buffer[:window_size]
            buffer = buffer[shift_amount:]

    # return the remainder, if any, to ensure we at least return 1 full frame
    if buffer is not None and len(buffer) < window_size:
        shape = buffer.shape
        if len(shape) == 2:
            new_sample = np.zeros((window_size - len(buffer), shape[1]))
        else:
            new_sample = np.zeros((window_size - len(buffer)))
        buffer = np.concatenate((buffer, new_sample))
        yield buffer[:window_size]
 General windowing and merging generator that concatenates & shifts samples through a sliding window frame 
General windowing and merging generator that concatenates & shifts samples through a sliding window frame
General windowing and merging generator that concatenates & shifts samples through a sliding window frame
def sliding_window_frame(source, window_size, shift_amount):
    buffer = None
    for new_samples in source:
        if np.isscalar(new_samples):
            new_samples = (new_samples,)
        if buffer is None:
            buffer = new_samples
        else:
            buffer = np.concatenate((buffer, new_samples))
        while len(buffer) >= window_size:
            yield buffer[:window_size]
            buffer = buffer[shift_amount:]
    if buffer is not None and len(buffer) < window_size:
        shape = buffer.shape
        if len(shape) == 2:
            new_sample = np.zeros((window_size - len(buffer), shape[1]))
        else:
            new_sample = np.zeros((window_size - len(buffer)))
        buffer = np.concatenate((buffer, new_sample))
        yield buffer[:window_size]
def sliding_window_frame ( source , window_size , shift_amount ) : buffer = None for new_samples in source : if np . isscalar ( new_samples ) : new_samples = ( new_samples , ) if buffer is None : buffer = new_samples else : buffer = np . concatenate ( ( buffer , new_samples ) ) while len ( buffer ) >= window_size : yield buffer [ : window_size ] buffer = buffer [ shift_amount : ] if buffer is not None and len ( buffer ) < window_size : shape = buffer . shape if len ( shape ) == 2 : new_sample = np . zeros ( ( window_size - len ( buffer ) , shape [ 1 ] ) ) else : new_sample = np . zeros ( ( window_size - len ( buffer ) ) ) buffer = np . concatenate ( ( buffer , new_sample ) ) yield buffer [ : window_size ]
General windowing and merging generator that concatenates & shifts samples through a sliding window frame
General windowing and merging generator that concatenates & shifts samples through a sliding window frame
""" General windowing and merging generator that concatenates & shifts samples through a sliding window frame """ # Source is a container or generator that returns numpy vectors # We buffer them and return arrays of length window_size, shifted by shift_amount  # if new_samples is a scalar, turn it into a 1-element tuple     # return the remainder, if any, to ensure we at least return 1 full frame
source
window_size
shift_amount