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_samples

librosa.time_to_samples(times, *, sr=22050)[source]

Convert timestamps (in seconds) to sample indices.

Parameters:
timesnumber or np.ndarray

Time value or array of time values (in seconds)

srnumber > 0

Sampling rate

Returns:
samplesint or np.ndarray [shape=times.shape, dtype=int]

Sample indices corresponding to values in times

See also

time_to_frames

convert time values to frame indices

samples_to_time

convert sample indices to time values

Examples

>>> librosa.time_to_samples(np.arange(0, 1, 0.1), sr=22050)
array([    0,  2205,  4410,  6615,  8820, 11025, 13230, 15435,
       17640, 19845])