pythonpyaudio

What does the number of channels mean in pyaudio?


From all the different questions that I referred to, I observed that people usually use the following configuration for pyaudio:

FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5 #depends how much you want to record.

With this configuration, the size of the recorded file (let's say sample.wav) will be 41000(RATE) * 4(sizeofeachsample) *5 (duration) = 0.882 Kb, and if we use Channel=1, then the size will be half of it and accordingly for other values. Can someone tell me what CHANNEL really means and what other changes will it have if we use different values?

What is the difference if we use CHANNEL=1` or `2` or `3`...?


Solution

  • Channel refers to the number of audio streams to use. Many modern computer speaker setups and audio files will have two channels for stereo output, one for the left speaker and the right speaker.

    Note that buffers will usually interleave the data of different channels. That is, if one channel has the following data:

    [0,1,2,3,4,5]

    and another has:

    [9,10,11,12,13,14]

    Then the buffer will contain: [0,9,1,10,2,11,3,12,4,13,5,14]