PsychoPy stops playing audio files halfway through experiment but continues otherwise

I’m preparing an EEG script in the coder (version 2026.2.4, Windows) in which I separately present video files (without audio) and audio files. During a testrun, I noticed that somewhere during the experiment, the audio cuts out and does not turn back on again in the next trial. The experiment does not crash or throw warnings, and the videos keep playing as if nothing is wrong.

To isolate the issue, I wrote a very small-scale test script, which only plays the audio files (so no EEG triggers, text screens, or video files). In this case, the same issue occurs. I have 32 short (approx. 3 second, 250 kB) audio files (48 kHz, mono). Each is supposed to be played in total 6 or 7 times throughout the experiment, for a total of 207 trials. I use audioLib = ‘ptb’ and audioLatencyMode = 1.

I tried both to load all sounds in advance to a library ({filename: SoundPTB object, …}), accessing as needed. Alternatively, I’ve tried loading the sound (using sound.Sound()) from the file path on each trial. I have also tried creating one sound object and changing the file using .setSound() on each trial. All these approaches result in the same problem. I’ve had one successful run I believe, showing that the problem certainly does not occur at the same time each time, or at the same file. What could be going on?

Some more clues: even when trying to play the same sound for 207 trials, the sound is lost after approximately 90 iterations.

I am playing the sound through an external audio interface (Arturia Minifuse 1), but that does not seem to be the issue. Other experiments in my lab have had no issues with this device.

Dear Floris,

Have you tried making sure you set the duration of the sound component to be a singular, that is longer than your longest sound file? I know psychopy will run into issues where setting the duration of the sound file to be the length of the sound file, or just allowing it to end after the sound file ends, has had issues similar to yours occur. Then the sound file does not “finish” properly and then sound breaks.

For more intensive debugging, I would first set the duration of the routine where the sound component is presented to be some arbitrary value that is well above your sound file lengths (e.g. 10 seconds). Run it, see what happens. Then set the sound component to be some arbitrarily large value like 6 seconds, with the routine itself still be longer. Then make sure there is routine of at least 1-2 seconds inbetween sound stimuli trials.

The other thing, is does it happen only after ~70-90 trials? Or can it happen earlier? I know you said you had a successful run, but does the issue occur within the first 10-30 trials ever?

Have you tried running the experiment using the computer’s basic audio driver, and playing through some regular speakers? I know other experiments have not had the same problem occur, but it’s always best to check all possible points of failure.

Issac