Audio playback sounds strange after inconsistent number of trials

Hi there!

I have a question related to audio playback in Pscyhopy coder. I started building the experiment in Psychopy builder, but transformed it to code when I realised I couldn’t do everything necessary in the builder. I use Psychopy version 2024.1.5 The experiment is rather simple, just playing audio to participants through Etymotics ER2SE earphones via a Fireface UFX II audio interface. While the audio is playing, participants look at a circle on the screen. The experiment is done by two participants at the same time, using two monitors in addition to the experimenter’s monitor.

The issue I am running into is that the audio playback seems fine the first time I run the experiment. However, after an inconsistent number of times running the experiment, at some point the audio starts to sound strange. I think it is a problem with the sampling rate being lower, as the audio sounds slower and it has a strange ‘ticking sound’ while playing. It also does not
finish before the next trial starts. Because the problem is inconsistent, I am not completely sure what the problem is. I would love to hear if anyone else has had any similar problems and how to potentially fix this. Thank you very much!

Does the problem get resolved with a reboot? I am sure you are aware, but there are multiple audio backends that Psychopy can hook into when playing sounds. It would be helpful to know which you are using, and if the problem persists with multiple backends: Sound - for audio playback — PsychoPy v2025.2.1

Context for what I am going to say next: I started using Psychopy circa 2010, and Python and Psychopy were both very different 15 years ago. My experiences trying to do sound in Python are from that era, and all that remains in my mind from that experience is a general feeling of apprehension. I am sure that is completely unwarranted in 2025.

That being said, when my experiments involve sound/music these days, I tend to load those audio files into a separate program like MusikCube that I can control over a network connection from another computer. The experimenter controls the music from their computer, while MusikCube runs in the background on the computers also running Psychopy. GitHub - clangen/musikcube: a cross-platform, terminal-based music player, audio engine, metadata indexer, and server in c++

This has the advantage of completely isolating the processes running Psychopy and those running the music, and the computer can run them truly in parallel. Python struggles with parallelization, and Psychopy is essentially single threaded. Because sound and vision are separate modalities, I think most experiments will tend to have sound and visual stimuli in “parallel”… but Python does not really do parallel, and that might be where some of the flakiness comes from.

Sorry to not be of more help!