Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Temporal Jitter in auditory stimuli presentation with pyaudio

edited December 2015 in OpenSesame


I'm preparing an experiment with sequences of four audio stimuli at 200ms each. So, each sequence has a duration 4x200ms = 800ms. At first I used a sampler item specifying the sound file: [sound1].wav, where "sound1" is the first column in my experiment loop. The result was fine but after reading in the documentation that is preferable to use pyaudio ("if you require very accurate temporal precision when presenting auditory stimuli you may want to write an inline_script that plays back sound using a different module, such as PyAudio.") I decided to change the implementation. So I followed the example presented here: I used the "play" example and I changed only this part to fit my experiment:

# inline_script item

OUTPUT_FILE = "/Users/test/Documents/OpenSesame/SESSION_B_2.opensesame/pool/%s.wav" % self.get('sound1')

wf =, 'rb')

Once I finished the implementation and I run the experiment, there was definitely a noticeable delay in the stimuli presentation.

I chose pyaudio to avoid any temporal jitter and finally the result was worse. Is there something wrong with my implementation? Thank you very much!


  • edited 8:35PM


    It seems like you're doing everything right, but also like you're confusing jitter and delay (or latency).

    • jitter is variability in playback onset. For example, if playback is sometimes delayed by 10 ms, and sometimes by 200 ms, then jitter is high; however, if playback is always delayed by about 200 ms then jitter is low.
    • delay is the time between the moment that you want playback to start, and the moment that playback actually starts. This can be very high, but stable, in which case you have a high delay with little jitter.

    What you're noticing is, I assume, a high delay. In my experience, pyaudio generally has a lower jitter than pygame for sound playback, even though the delay may the same or higher. Does that make sense? I should also point out that this is my general experience, and may not be the case on all systems--it's really a matter of testing what works best.


    There's much bigger issues in the world, I know. But I first have to take care of the world I know.

  • edited 8:35PM

    Hi Sebastiaan,

    Thank you for you immediate response!
    You are right delay is the appropriate term for what I notice and it is actually high. So, after trying both pygame & pyaudio I will go for the first one which works best.
    I assume we can consider the issue resolved.


Sign In or Register to comment.