def blocks(file, blocksize=None, overlap=0, frames=-1, start=0, stop=None,
           dtype='float64', always_2d=False, fill_value=None, out=None,
           samplerate=None, channels=None,
           format=None, subtype=None, endian=None, closefd=True):
    """Return a generator for block-wise reading.

    By default, iteration starts at the beginning and stops at the end
    of the file.  Use `start` to start at a later position and `frames`
    or `stop` to stop earlier.

    If you stop iterating over the generator before it's exhausted,
    the sound file is not closed. This is normally not a problem
    because the file is opened in read-only mode. To close the file
    properly, the generator's ``close()`` method can be called.

    Parameters
    ----------
    file : str or int or file-like object
        The file to read from.  See :class:`SoundFile` for details.
    blocksize : int
        The number of frames to read per block.
        Either this or `out` must be given.
    overlap : int, optional
        The number of frames to rewind between each block.

    Yields
    ------
    numpy.ndarray or type(out)
        Blocks of audio data.
        If `out` was given, and the requested frames are not an integer
        multiple of the length of `out`, and no `fill_value` was given,
        the last block will be a smaller view into `out`.

    Other Parameters
    ----------------
    frames, start, stop
        See :func:`read`.
    dtype : {'float64', 'float32', 'int32', 'int16'}, optional
        See :func:`read`.
    always_2d, fill_value, out
        See :func:`read`.
    samplerate, channels, format, subtype, endian, closefd
        See :class:`SoundFile`.

    Examples
    --------
    >>> import soundfile as sf
    >>> for block in sf.blocks('stereo_file.wav', blocksize=1024):
    >>>     pass  # do something with 'block'

    """
    with SoundFile(file, 'r', samplerate, channels,
                   subtype, endian, format, closefd) as f:
        frames = f._prepare_read(start, stop, frames)
        for block in f.blocks(blocksize, overlap, frames,
                              dtype, always_2d, fill_value, out):
            yield block