librosa.core.samples_to_time¶
-
librosa.core.
samples_to_time
(samples, sr=22050)[source]¶ Convert sample indices to time (in seconds).
Parameters: - samples : np.ndarray
Sample index or array of sample indices
- sr : number > 0
Sampling rate
Returns: - times : np.ndarray [shape=samples.shape, dtype=int]
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)) 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])