Skip to content

Instantly share code, notes, and snippets.

@davidrft
Created October 9, 2019 19:52
Show Gist options
  • Save davidrft/7fc1c38581dc7f0d3c3ad372de214485 to your computer and use it in GitHub Desktop.
Save davidrft/7fc1c38581dc7f0d3c3ad372de214485 to your computer and use it in GitHub Desktop.
Generator of windows from an audio file to short-time analysis
def windows(array, window_size, overlap=0):
""" Generator of windows from an audio file to short-time analysis
Keyword arguments:
array -- Array of audio samples
window_size -- Size of the window that will be generated
overlap -- Overlap of windows to be accounted for when generating new ones
"""
overlap_factor = (1 - overlap)
head, tail = 0, window_size
while head < len(array):
window = array[head:tail]
head += int(window_size * overlap_factor)
tail += int(window_size * overlap_factor)
yield window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment