This has me completely stumped - I don’t know what I’m doing wrong. What I’m trying to do is:
- present an auditory prime (a single word) to the participant while the screen is blank;
- wait until the prime has finished playing
- present a visual target (a single word presented orthographically) which the participant has to read aloud
- measure their RT in the speech signal (which I record using psychopy.microphone)
(I read somewhere that pyo tends to start recording before the actual microphone.record() call, so I also record the auditory prime and worry about finding the vocal RTs later, off-line. I don’t think this detail matters for my problem, though.)
(5. While doing all this, I also record EEG activity, but that is tangential to the issue.)
Code is below (pardon any formatting issues). ‘prime’ and ‘ortho’ are strings representing the (auditory) prime and (visual) target, ‘snd’ is a psychopy.Sound object that I created earlier in the code.
dur = snd.getDuration() write('+') win.flip() core.wait(1) win.flip() write(ortho) parallel.setData(11) mic.record(dur+2, filename='rec/'+str(ppn)+'_'+prime+'_'+ortho+'_'+str(rt.getTime())+'.wav', block=False) snd.play() core.wait(dur) win.flip() core.wait(2) parallel.setData(10)
The problem is in the
core.wait(dur) between the
snd.play() and the
win.flip(). From my understanding, the above code should play the sound, wait until it has exactly finished playing, and then flip the window (revealing the orthographic target).
What I am seeing, however, is that it only waits about half as long as it should, meaning that the window is flipped while the sound is still playing. I am completely stumped by this - what am I missing?
EDIT: after some debugging, it looks like the issue is in pyglet; it looks like the problem is not core.wait() or snd.getDuration() as I originally suspected, but rather that the win.flip() is somehow ‘anticipated’ by pyglet (similarly to how pyo has been known to ‘anticipate’ microphone.record()?). Is that plausible? Strangely enough, it looks like I have found a workaround: sleep for an extra 0.5 seconds right before the call to
win.flip() (but after other timing-dependent things).