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_stereo
- librosa.to_stereo(*, left, right, downmix=True, pad=True, norm=True, out=None)[source]
Combine two signals into a stereo signal.
- Parameters:
- leftnp.ndarray [shape=(…, n)] or None
Left channel signal. Multi-channel is supported.
- rightnp.ndarray [shape=(…, m)] or None
Right channel signal. Multi-channel is supported.
- downmixbool
If True, downmix the left and right channels to mono before combining.
If False, the left and right signals are additively combined.
- padbool
If True, pad the shorter channel with zeros to match the length of the longer channel. If False, the longer channel is trimmed to match the length of the shorter channel.
- normbool
If True (default), signals are combined by averaging.
If False, signals are combined by summing.
- outnp.ndarray [shape=(2, n_out)] or None
A pre-allocated output buffer. If provided, it must match the shape
(2, n_out), 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. IfNone(default), a new array is allocated.
- Returns:
- y_stereonp.ndarray [shape=(2, n_out)]
Stereo signal with left channel in the first row and right channel in the second row. If
outwas provided, this is the same object asout.
See also
Notes
At least one of left or right must be provided.
Examples
Combine two mono signals into a hard-panned stereo signal
>>> y1 = librosa.tone(440.0, sr=22050, duration=1.0) >>> y2 = librosa.tone(550.0, sr=22050, duration=1.0) >>> y_stereo = librosa.to_stereo(left=y1, right=y2)
Upmix a mono signal into the left or right channel in stereo
>>> y_left = librosa.to_stereo(left=y1, right=None) >>> y_right = librosa.to_stereo(left=None, right=y2)
Downmix a stereo signal into the left channel, and mix a third mono signal into the right channel
>>> y3 = librosa.tone(660.0, sr=22050, duration=1.0) >>> y_mix = librosa.to_stereo(left=y_stereo, right=y3, downmix=True)
Keep the original stereo signal separated, but mix a third signal into the right channel:
>>> y_mix = librosa.to_stereo(left=y_stereo, right=y3, downmix=False)