Caution

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

librosa.to_multi

librosa.to_multi(*signals, downmix=True, pad=True, norm=True, out=None)[source]

Combine multiple signals into a multi-channel signal.

Parameters:
*signalsnp.ndarray [shape=(…, n)]

One or more signals to combine into a multi-channel signal. Each input signal can be mono or multi-channel, and they need not all have identical lengths.

downmixbool

If True, downmix each input signal to mono before combining.

If False, the input signals are additively combined, and all must have identical channel layouts (shape excluding the trailing length dimension).

padbool

If True, pad the output to match the length of the longest input signal.

If False, trim the output to match the length of the shortest input signal.

normbool

If True (default), signals are combined by averaging.

If False, signals are combined by summing.

outnp.ndarray [shape=(m, n_out) or shape=(…, n_out)] or None

A pre-allocated output buffer. If provided, it must match the result shape, and its dtype must be at least as precise as the result dtype; it is zeroed and filled in place and returned, avoiding a new allocation. If None (default), a new array is allocated.

Returns:
y_multinp.ndarray [shape=(m, n_out) or shape=(…, n_out)]

Multi-channel combination of the input signals, where m corresponds to the number of signals (if downmix=True), and n_out is the length of the output signal determined by the padding mode. If out was provided, this is the same object as out.

Examples

Combine three mono signals of different lengths into a multi-channel signal

>>> y1 = librosa.tone(440.0, sr=22050, duration=1.0)
>>> y2 = librosa.tone(550.0, sr=22050, duration=1.0)
>>> y3 = librosa.tone(660.0, sr=22050, duration=2.0)
>>> y_multi = librosa.to_multi(y1, y2, y3, pad=True)
>>> y_multi.shape
(3, 44100)