

@cache
def resample(y, orig_sr, target_sr, res_type='kaiser_best', fix=True, scale=False, **kwargs):
    "Resample a time series from orig_sr to target_sr\n\n    Parameters\n    ----------\n    y : np.ndarray [shape=(n,) or shape=(2, n)]\n        audio time series.  Can be mono or stereo.\n\n    orig_sr : number > 0 [scalar]\n        original sampling rate of `y`\n\n    target_sr : number > 0 [scalar]\n        target sampling rate\n\n    res_type : str\n        resample type (see note)\n\n        .. note::\n            By default, this uses `resampy`'s high-quality mode ('kaiser_best').\n            If `res_type` is not recognized by `resampy.resample`, it then\n            falls back on `scikits.samplerate` (if it is installed)\n\n            If both of those fail, it will fall back on `scipy.signal.resample`.\n\n            To force use of `scipy.signal.resample`, set `res_type='scipy'`.\n\n    fix : bool\n        adjust the length of the resampled signal to be of size exactly\n        `ceil(target_sr * len(y) / orig_sr)`\n\n    scale : bool\n        Scale the resampled signal so that `y` and `y_hat` have approximately\n        equal total energy.\n\n    kwargs : additional keyword arguments\n        If `fix==True`, additional keyword arguments to pass to\n        `librosa.util.fix_length`.\n\n    Returns\n    -------\n    y_hat : np.ndarray [shape=(n * target_sr / orig_sr,)]\n        `y` resampled from `orig_sr` to `target_sr`\n\n\n    See Also\n    --------\n    librosa.util.fix_length\n    scipy.signal.resample\n\n    Examples\n    --------\n    Downsample from 22 KHz to 8 KHz\n\n    >>> y, sr = librosa.load(librosa.util.example_audio_file(), sr=22050)\n    >>> y_8k = librosa.resample(y, sr, 8000)\n    >>> y.shape, y_8k.shape\n    ((1355168,), (491671,))\n\n    "
    util.valid_audio(y, mono=False)
    if (orig_sr == target_sr):
        return y
    ratio = (float(target_sr) / orig_sr)
    n_samples = int(np.ceil((y.shape[(- 1)] * ratio)))
    try:
        y_hat = resampy.resample(y, orig_sr, target_sr, filter=res_type, axis=(- 1))
    except NotImplementedError:
        if (_HAS_SAMPLERATE and (res_type != 'scipy')):
            warnings.warn('scikits.samplerate resampling is deprecated as of librosa version 0.4.3.\n\tSupport will be removed in librosa version 0.5.', category=DeprecationWarning)
            y_hat = samplerate.resample(y.T, ratio, res_type).T
        else:
            y_hat = scipy.signal.resample(y, n_samples, axis=(- 1))
    if fix:
        y_hat = util.fix_length(y, n_samples, **kwargs)
    if scale:
        y_hat /= np.sqrt(ratio)
    return np.ascontiguousarray(y_hat, dtype=y.dtype)

dataset/ETHPy150Open bmcfee/librosa/librosa/core/audio.py resample/VarMisuse@206/1034 `y_hat`->`y`