| Reference | Downloads | Github

Setting buffer size for audio in PsychoPy

[ StandAlone Psychopy, Builder and Coder Views. Windows 7 ]


We’ve been coding some new experiments and we found a hardware-related issue which we solved with a dedicated sound card.
The problem is, when running the experiment, PsychoPy still uses the wrong audio device to play the desired sound.

We’ve been using Pyo’s functions to get the available audio devices, and then setting it to the proper device.

So for instance, in a code component set at the start of the experiment where we get the devices:


and set them to the correct one (for example, number 6):


We tested printing to console getting the current device being used for audio display and we get the original device (for example, number 1), like PsychoPy is simply ignoring the previously given order.
Now, I’m aware the PsychoPy has a “Preferences” menu where you can set the desired audio library. we selected Pyo instead of PyGame but the device used is still the same.

Now, we are kind of forced to use the default device, so we are trying to control the buffer size to somehow deal with the issue. But we can’t find an option for that.
Also, is there any way to print to console the full data of the Sound object being used by PsychoPy to play a given audio file? I mean, like kHz, buffer size, etc. Because the Sound data provided at the documentation doesn’t mention such a feature.

Sorry for the long post, hopefully I’ve detailed the full issue.
Any help would be much appreciated.

What version of PsychoPy are you using?

In 1.85.1 there’s now a setting in preferences to select your device as well as the overall library (although this is new and may have issues). There’s also now the sounddevice backend (which I would recommend over pyo)

The sample rate is determined by the first sound that gets played.

Finding out about the current stream is dependent on which lib you’re using. For sounddevice I think you can do print(mySound._sdStream)


Hi Jon,

I can’t remember the exact version of the PsychoPy distribution being used at the lab, but I think its less than 1 year old. Anyways, we are also testing on our own laptops with the most recent version.

That being said, the device per se isn’t such a critical issue compared to the buffer size issue. Regardless of the device being used (which we managed to control in the end), we are still dealing with buffer size issues.

For example, when running the following code:

from psychopy import core, sound
octaves = [3, 6]
notes = ['A','B']
sampleRates = [22050, 44100]
bits = [4, 16]
buffers = [64, 1024]

for buffer in buffers:
    for sampleRate in sampleRates:
        sound.init(sampleRate, buffer)
        for bit in bits:
            for octave in octaves:
                for note in notes:
                    stim = sound.Sound(value=note, octave=octave, bits=bit, secs=0.2)
                    print 'playing params:', buffer, sampleRate, bit

PsychoPy’s output prints the sound object’s data accordingly, with buffers from 64 to 1024 as expected. But when we run ASIO4ALL’s utilities, we get the online info of the sound being played, and it shows that the buffer size is actually ranging from 1024 to 2048, so we’re kind of confused because of this contradiction between both info sources.

Any ideas on why could PsychoPy and ASIO4ALL be seeing different values for buffer size?

Additional info that could help:

  • ASIO4ALL’s default buffer size is 128.
  • We’ve also tested with a default value of 64, with the same results.