Timing issue with sound components on eyetracking experiment

OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 2023.2.1
Standard Standalone? (y/n) Yes
What are you trying to achieve?: I am trying to make a sound-based experiment where 12 syllables are presented per trial, in a loop with 2 trials per repetition. The idea is to switch between routines via an eyetracking component (i.e if the participant looks to an ROI on the right while the first routine runs, it switches to the second, and viceversa). The issue is that when switching between routines, the syllables play on top of each other for a few frames.

What did you try to make it work?: I have included a code component that does the following (in the every frame tab):

if roi_left_2.currentLookTime > 0.2:
    sound_37.stop()
    sound_37.status=FINISHED
    sound_38.stop()
    sound_38.status=FINISHED
    sound_39.stop()
    sound_39.status=FINISHED
    sound_40.stop()
    sound_40.status=FINISHED
    sound_41.stop()
    sound_41.status=FINISHED
    sound_42.stop()
    sound_42.status=FINISHED
    sound_43.stop()
    sound_43.status=FINISHED
    sound_44.stop()
    sound_44.status=FINISHED
    sound_45.stop()
    sound_45.status=FINISHED
    sound_46.stop()
    sound_46.status=FINISHED
    sound_47.stop()
    sound_47.status=FINISHED
    sound_48.stop()
    sound_48.status=FINISHED
if t>=0.25:
    sound_37.stop()
    sound_37.status=FINISHED
elif t>=0.62:
    sound_38.stop()
    sound_38.status=FINISHED
elif t>=0.99:
    sound_39.stop()
    sound_39.status=FINISHED
elif t>=1.36:
    sound_40.stop()
    sound_40.status=FINISHED
elif t>=1.73:
    sound_41.stop()
    sound_41.status=FINISHED
elif t>=2.10:
    sound_42.stop()
    sound_42.status=FINISHED
elif t>=2.47:
    sound_43.stop()
    sound_43.status=FINISHED
elif t>=2.84:
    sound_44.stop()
    sound_44.status=FINISHED
elif t>=3.21:
    sound_45.stop()
    sound_45.status=FINISHED
elif t>=3.58:
    sound_46.stop()
    sound_46.status=FINISHED
elif t>=3.95:
    sound_47.stop()
    sound_47.status=FINISHED
elif t>=4.31:
    sound_48.stop()
    sound_48.status=FINISHED

I also added another code that prints which sound is playing every frame.
What specifically went wrong when you tried that?:
Even though I specifically stop all sounds once their time is up, they play on top of each other at the end of the routine. The code that prints which sound is playing never shows any sounds playing at the same time though.

Is it possible that by adding so many conditions each frame I am overloading the computer so that it loads sounds at random times?

Hi There,

Are you able to share your Builder file?

Just to check does something like this work? (this switches between sounds when the mouse hovers over a ROI - a bit like how you describe your eye tracking task). Note that I tried this in 2023.2.3 and it seemed to work ok.

Becca
sound_switching.psyexp (24.3 KB)