| Reference | Downloads | Github

Timing in audio playback and recording

I would appreciate any insight you could offer on solving the following mysteries. Thank you for your time. Code snipit is below. Win7, stock Python/PsychoPy. Problem occurs with multiple IDEs.

I want to play a short audio file (<1 sec) and then begin recording immediately after playback. I think this is what the code below should do. Instead, what is happening, as the spectrogram shows, is that recording starts about 290-300ms before it should. This behavior is quite consistent and reliable. It is as though core.wait() is being ignored.

mic.getMarkgetMarkerOnset() usually returns a value of 10-15ms, which seems about right if one measures from the end of the sound file that was played (see spectrogram). Rarely will it return what should be the true value of about 300ms.

If mic.record() is placed BEFORE, a similar delay of 300ms is found before audio playback begins, as though pyo must reinitialize for output and requires this overhead.

from psychopy import prefs
prefs.general[‘audioLib’] = [‘pyo’]

from psychopy import visual, microphone, sound, core, event, logging, data, gui
import os

core.checkPygletDuringWait = False

buffer_size = 128
rate = 48000
sound.init(buffer=buffer_size, rate=rate)

mic = microphone.AdvAudioCapture(chnl=1)

rec_duration = 1.0
snd = sound.Sound(“steal.wav”)
sndDur = snd.getDuration()

mic.record(rec_duration, filename=“test.wav”)

onset, offset = mic.getMarkerOnset(chunk=64, secs=0.5, filename=“test.wav”)
print onset, offset