How do I set the PTB audio latency mode to "4" (critical)?

The latency modes are described in Sound - for audio playback — PsychoPy v2021.2.4
but I couldn’t see any guidance about how to set them. The PTB Sound class doesn’t mention it (Sound - for audio playback — PsychoPy v2021.2.4).

Would the following work?
from psychopy import prefs
prefs.hardware[‘audioLib’] = [‘ptb’]
prefs.hardware[‘audioLatencyMode’] = [4]. # <<< Is it this simple? Should the 4 be in quotes?
from psychopy import sound

When I inspect the default audioLatencyMode (print(prefs.hardware[‘audioLatencyMode’])), the output is in quotes ( ‘3’ ), so I assume you indeed have to provide it between quotes. (haven’t tested this though).

I suspect that it will give an error anyway when you run some audio with the wrong configuration?

Yes indeed, that now runs. So thanks.

My measurements (40 reaction times to the onset of audio for latency modes of each of '3" and ‘4’) show no significant difference in either the correlation between real reaction time and Psychopy’s measurement of that reaction time, nor in the spread. In both cases Psychopy’s RT measurements are consistently about 25 ms slower than reality (in the range between 140 ms and 1 second), and the standard deviation of the signed difference between real and psychophysics reaction times is 0.005 sec (i.e. 5 ms).

I can confirm that this code does work in changing the latency mode, because if I used the same code to change it to ‘0’ (meaning we don’t care about latency, just be a good computational citizen), then the average lag increased from 25 ms to 60 ms and the standard deviation of real-psychopy increased from 5 ms to about 30 ms.

Note that a standard deviation of 60 ms means 2/3 of all RT measurements will be up to 30 ms too slow or too fast, and the remaining 1/3 will be worse than that. So don’t use “0” is you care at all about reaction time.

2017 MacBook Pro running Big Sur 11.4, reaction time to either the space bar or the return key. I play out the audio then wait for a keyboard response.