librosa.times_like

librosa.times_like(X, sr=22050, hop_length=512, n_fft=None, axis=-1)[source]

Return an array of time values to match the time axis from a feature matrix.

Parameters
Xnp.ndarray or scalar
  • If ndarray, X is a feature matrix, e.g. STFT, chromagram, or mel spectrogram.

  • If scalar, X represents the number of frames.

srnumber > 0 [scalar]

audio sampling rate

hop_lengthint > 0 [scalar]

number of samples between successive frames

n_fftNone or int > 0 [scalar]

Optional: length of the FFT window. If given, time conversion will include an offset of n_fft // 2 to counteract windowing effects when using a non-centered STFT.

axisint [scalar]

The axis representing the time axis of X. By default, the last axis (-1) is taken.

Returns
timesnp.ndarray [shape=(n,)]

ndarray of times (in seconds) corresponding to each frame of X.

See also

samples_like

Return an array of sample indices to match the time axis from a feature matrix.

Examples

Provide a feature matrix input:

>>> y, sr = librosa.load(librosa.ex('trumpet'))
>>> D = librosa.stft(y)
>>> times = librosa.times_like(D)
>>> times
array([0.   , 0.023, ..., 5.294, 5.317])

Provide a scalar input:

>>> n_frames = 2647
>>> times = librosa.times_like(n_frames)
>>> times
array([  0.00000000e+00,   2.32199546e-02,   4.64399093e-02, ...,
         6.13935601e+01,   6.14167800e+01,   6.14400000e+01])