Caution

You're reading the documentation for a development version. For the latest released version, please have a look at 0.10.2.

librosa.blocks_to_samples

librosa.blocks_to_samples(blocks, *, block_length, hop_length)[source]

Convert block indices to sample indices

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

Returns:
samplesnp.ndarray [shape=samples.shape, dtype=int]

The index or indices of samples corresponding to the beginning of each provided block.

Note that these correspond to the first sample index in each block, and are not frame-centered.

Examples

Get sample indices for each block in a stream

>>> filename = librosa.ex('brahms')
>>> 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_sample = librosa.blocks_to_samples(n, block_length=16,
...                                          hop_length=512)