def buf_to_float(x, n_bytes=2, dtype=np.float32):

    # Invert the scale of the data
    scale = 1./float(1 << ((8 * n_bytes) - 1))

    # Construct the format string
    fmt = '<i{:d}'.format(n_bytes)

    # Rescale and format the data buffer
    return scale * np.frombuffer(x, fmt).astype(dtype)
Convert an integer buffer to floating point values.
dataset/ETHPy150Open bmcfee/librosa/librosa/util/utils.py/buf_to_float