librosa.core.time_to_frames

librosa.core.time_to_frames(times, sr=22050, hop_length=512, n_fft=None)[source]

Converts time stamps into STFT frames.

Parameters:
times : np.ndarray [shape=(n,)]

time (in seconds) or vector of time values

sr : number > 0 [scalar]

audio sampling rate

hop_length : int > 0 [scalar]

number of samples between successive frames

n_fft : None 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 in STFT.

Note

This may result in negative frame indices.

Returns:
frames : np.ndarray [shape=(n,), dtype=int]

Frame numbers corresponding to the given times: frames[i] = floor( times[i] * sr / hop_length )

See also

frames_to_time
convert frame indices to time values
time_to_samples
convert time values to sample indices

Examples

Get the frame numbers for every 100ms

>>> librosa.time_to_frames(np.arange(0, 1, 0.1),
...                         sr=22050, hop_length=512)
array([ 0,  4,  8, 12, 17, 21, 25, 30, 34, 38])