Sound not playing after one second, but at the end of the routine

Hi everyone.

I’m trying to get a 25 second piece of sound to just play for the first 10 seconds through code, and then stop once my trials stop after 10 seconds.

My trials stop after 10 seconds which is perfect and what I need, however the sound doesn’t play after one second, it players at the end of the trials so after the 10 seconds., does anyone know this may occur?

Both of these are within each frame

if trial_timer.getTime() > 1:
    sound1.play()

if trial_timer.getTime() > 10:
    continueRoutine = False
    Recall_Practice.finished = True

Kind regards,

Rob

Hi Rob,

I suspect that your code gives the command to play the sound many times a second and maybe that leads to the problem. Does it help if you use the following?

if sound1.status == NOT_STARTED and trial_timer.getTime() > 1:

Hi Ajus,

I tried it, didn’t work, no sound is now playing. I do think your suggestion maybe correct though, in that it’s trying to play the sound lots due to checking per frame.

I did wonder if it was to do with the clock, but the trial length works perfectly.

I searched the forums, and I can get the sound to work off trials e.g.

if trial.n == 0:
 sound1.play()

if trial n ==20
 sound1.stop()

My problem is I need blocks of trials based off lengths of times, rather than trial number.

Kind regards,

Rob

Ahh, I think PTB sounds have different codes for their status: 1 for playing, 0 for not playing (Psychtoolbox-3 - PsychPortAudio(‘GetStatus’)). So maybe it’s

if sound1.status == 0 and trial_timer.getTime() > 1:

Ahh good catch. That might explain it, I am using PTB, let me try that!

Kind regards,

Rob

Hey, I fixed it. it’s way simpler than I initially thought.

I ended up doing in the begin tab.


if your_loop_name.thisN == 0:
    sound1.play()

and in the ever frames tab

if trial_timer.getTime() > 10:
    sound1.stop()
    continueRoutine = False
    Recall_Practice.finished = True

1 Like