Skip to main content

Buffer audio samples into fixed-sized blocks, with overlap

Project description

Python: Buffer audio samples into fixed-sized blocks, with overlap

This small utility package encapsulates a single-consumer, single-producer ringbuffer.

  • Populate the buffer with arrays of arbitrary-length samples
  • Query the buffer, and it returns arrays of a specified fixed length, optionally with overlap between successive blocks

It is designed primarily for applying the short-time Fourier transform (STFT) to successive blocks of an input audio stream (see below for example).

It is safe for usage in real-time audio applications, as no memory allocation or system I/O is done within the extend method.


To do block-sized buffering with overlap in conjunction with sounddevice:

import sounddevice as sd
import numpy as np
import blockbuffer

block_size = 1024
hop_size = 128

bb = blockbuffer.BlockBuffer(block_size=block_size,

def input_callback(data, frames, time, status):
    global bb
    for block in bb:
        block_windowed = block * np.hanning(block_size)
        block_spectrum = np.fft.rfft(block_windowed)

stream = sd.InputStream(callback=input_callback, channels=1)

Source code

Source code is available on GitHub.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for blockbuffer, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size blockbuffer-0.0.3.tar.gz (3.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page