Caution
You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.9.1.
librosa.core.blocks_to_time¶
- librosa.core.blocks_to_time(blocks, block_length, hop_length, sr)[source]¶
Convert block indices to time (in seconds)
- Parameters
- blocksnp.ndarray
Block index or array of block indices
- block_lengthint > 0
The number of frames per block
- hop_lengthint > 0
The number of samples to advance between frames
- srint > 0
The sampling rate (samples per second)
- Returns
- timesnp.ndarray [shape=samples.shape]
The time index or indices (in seconds) corresponding to the beginning of each provided block.
Note that these correspond to the time of the first sample in each block, and are not frame-centered.
See also
Examples
Get time indices for each block in a stream
>>> filename = librosa.util.example_audio_file() >>> sr = librosa.get_samplerate(filename) >>> stream = librosa.stream(filename, block_length=16, ... frame_length=2048, hop_length=512) >>> for n, y in enumerate(stream): ... n_time = librosa.blocks_to_time(n, block_length=16, ... hop_length=512, sr=sr)