Caution
You're reading the documentation for a development version. For the latest released version, please have a look at 0.10.2.
librosa.samples_to_time
- librosa.samples_to_time(samples, *, sr=22050)[source]
Convert sample indices to time (in seconds).
- Parameters:
- samplesnp.ndarray
Sample index or array of sample indices
- srnumber > 0
Sampling rate
- Returns:
- timesnp.ndarray [shape=samples.shape]
Time values corresponding to
samples
(in seconds)
See also
samples_to_frames
convert sample indices to frame indices
time_to_samples
convert time values to sample indices
Examples
Get timestamps corresponding to every 512 samples
>>> librosa.samples_to_time(np.arange(0, 22050, 512), sr=22050) array([ 0. , 0.023, 0.046, 0.07 , 0.093, 0.116, 0.139, 0.163, 0.186, 0.209, 0.232, 0.255, 0.279, 0.302, 0.325, 0.348, 0.372, 0.395, 0.418, 0.441, 0.464, 0.488, 0.511, 0.534, 0.557, 0.58 , 0.604, 0.627, 0.65 , 0.673, 0.697, 0.72 , 0.743, 0.766, 0.789, 0.813, 0.836, 0.859, 0.882, 0.906, 0.929, 0.952, 0.975, 0.998])