Caution
You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.10.2.
librosa.time_to_frames
- librosa.time_to_frames(times, *, sr=22050, hop_length=512, n_fft=None)[source]
Convert time stamps into STFT frames.
- Parameters:
- timesnp.ndarray [shape=(n,)]
time (in seconds) or vector of time values
- 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 in STFT.Note
This may result in negative frame indices.
- Returns:
- framesnp.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])