

def get_duration(y=None, sr=22050, S=None, n_fft=2048, hop_length=512, center=True):
    'Compute the duration (in seconds) of an audio time series or STFT matrix.\n\n    Examples\n    --------\n    >>> # Load the example audio file\n    >>> y, sr = librosa.load(librosa.util.example_audio_file())\n    >>> librosa.get_duration(y=y, sr=sr)\n    61.44\n\n    >>> # Or compute duration from an STFT matrix\n    >>> y, sr = librosa.load(librosa.util.example_audio_file())\n    >>> S = librosa.stft(y)\n    >>> librosa.get_duration(S=S, sr=sr)\n    61.44\n\n    >>> # Or a non-centered STFT matrix\n    >>> S_left = librosa.stft(y, center=False)\n    >>> librosa.get_duration(S=S_left, sr=sr)\n    61.3471201814059\n\n    Parameters\n    ----------\n    y : np.ndarray [shape=(n,), (2, n)] or None\n        audio time series\n\n    sr : number > 0 [scalar]\n        audio sampling rate of `y`\n\n    S : np.ndarray [shape=(d, t)] or None\n        STFT matrix, or any STFT-derived matrix (e.g., chromagram\n        or mel spectrogram).\n\n    n_fft       : int > 0 [scalar]\n        FFT window size for `S`\n\n    hop_length  : int > 0 [ scalar]\n        number of audio samples between columns of `S`\n\n    center  : boolean\n        - If `True`, `S[:, t]` is centered at `y[t * hop_length]`\n        - If `False`, then `S[:, t]` begins at `y[t * hop_length]`\n\n    Returns\n    -------\n    d : float >= 0\n        Duration (in seconds) of the input time series or spectrogram.\n    '
    if (y is None):
        assert (S is not None)
        n_frames = S.shape[1]
        n_samples = (n_fft + (hop_length * (n_frames - 1)))
        if center:
            n_samples = (hop_length - (2 * int((n_fft / 2))))
    else:
        util.valid_audio(y, mono=False)
        if (y.ndim == 1):
            n_samples = len(y)
        else:
            n_samples = y.shape[(- 1)]
    return (float(n_samples) / sr)

dataset/ETHPy150Open bmcfee/librosa/librosa/core/audio.py get_duration/VarMisuse@84/730 `n_samples`->`hop_length`