Configure Channel Maps for Multi-channel Audio
masterIf you need to record or play only a subset of available channels, use the channels parameter.
Backend Behavior:
- WASAPI (Windows) & CoreAudio (macOS): Indices refer to the physical output channels of the device.
- PulseAudio (Linux): Specifiers refer to logical channel positions. You can use integer indices or name strings (e.g.,
'left','right').
PulseAudio Channel Names:
Common identifiers include: 'mono' (index -1), 'left', 'right', 'center', 'rear-center', 'rear-left', 'rear-right', 'lfe', 'front-left-of-center', 'front-right-of-center', 'side-left', and 'side-right'.
To see the mapping of positions to indices for your specific backend, call sc.channel_name_map().
import soundcard as sc
# Record one second of audio from backend channels 0, 1, 2, and 3
data = default_mic.record(samplerate=48000, channels=[0, 1, 2, 3], numframes=48000)
# Play back the recorded audio in reverse channel order using names (PulseAudio only)
default_speaker.play(data=data, channels=['right', 'left'], samplerate=48000)