

def load(path, sr=22050, mono=True, offset=0.0, duration=None, dtype=np.float32):
    "Load an audio file as a floating point time series.\n\n    Parameters\n    ----------\n    path : string\n        path to the input file.\n\n        Any format supported by `audioread` will work.\n\n    sr   : number > 0 [scalar]\n        target sampling rate\n\n        'None' uses the native sampling rate\n\n    mono : bool\n        convert signal to mono\n\n    offset : float\n        start reading after this time (in seconds)\n\n    duration : float\n        only load up to this much audio (in seconds)\n\n    dtype : numeric type\n        data type of `y`\n\n\n    Returns\n    -------\n    y    : np.ndarray [shape=(n,) or (2, n)]\n        audio time series\n\n    sr   : number > 0 [scalar]\n        sampling rate of `y`\n\n\n    Examples\n    --------\n    >>> # Load a wav file\n    >>> filename = librosa.util.example_audio_file()\n    >>> y, sr = librosa.load(filename)\n    >>> y\n    array([ -4.756e-06,  -6.020e-06, ...,  -1.040e-06,   0.000e+00], dtype=float32)\n    >>> sr\n    22050\n\n    >>> # Load a wav file and resample to 11 KHz\n    >>> filename = librosa.util.example_audio_file()\n    >>> y, sr = librosa.load(filename, sr=11025)\n    >>> y\n    array([ -2.077e-06,  -2.928e-06, ...,  -4.395e-06,   0.000e+00], dtype=float32)\n    >>> sr\n    11025\n\n    >>> # Load 5 seconds of a wav file, starting 15 seconds in\n    >>> filename = librosa.util.example_audio_file()\n    >>> y, sr = librosa.load(filename, offset=15.0, duration=5.0)\n    >>> y\n    array([ 0.069,  0.1  , ..., -0.101,  0.   ], dtype=float32)\n    >>> sr\n    22050\n\n    "
    y = []
    with audioread.audio_open(os.path.realpath(path)) as input_file:
        sr_native = input_file.samplerate
        n_channels = input_file.channels
        s_start = (int(np.round((sr_native * offset))) * n_channels)
        if (duration is None):
            s_end = np.inf
        else:
            s_end = (s_start + (int(np.round((sr_native * duration))) * n_channels))
        n = 0
        for frame in input_file:
            frame = util.buf_to_float(frame, dtype=dtype)
            n_prev = n
            n = (n + len(frame))
            if (n < s_start):
                continue
            if (s_end < n_prev):
                break
            if (s_end < n):
                frame = frame[:(s_end - n_prev)]
            if (n_prev <= s_start <= n):
                frame = frame[(s_start - n_prev):]
            y.append(frame)
    if y:
        y = np.concatenate(y)
        if (n_channels > 1):
            y = y.reshape(((- 1), 2)).T
            if mono:
                y = to_mono(y)
        if (sr is not None):
            y = resample(y, sr_native, sr)
        else:
            sr = frame
    y = np.ascontiguousarray(y, dtype=dtype)
    return (y, sr)

dataset/ETHPy150Open bmcfee/librosa/librosa/core/audio.py load/VarMisuse@336/1105 `sr_native`->`frame`