# Sound timing question

**URL:** <https://discourse.psychopy.org/t/sound-timing-question/10677>\
**Category:** Builder\
**Created:** [January 22, 2020, 4:48pm UTC](https://discourse.psychopy.org/t/sound-timing-question/10677 "2020-01-22T16:48:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Buehner](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/marc_buehner/32/3476_2.png) [@Marc\_Buehner](https://discourse.psychopy.org/u/Marc_Buehner)\
**Post date:** [January 22, 2020, 4:48pm UTC](https://discourse.psychopy.org/t/sound-timing-question/10677/1 "2020-01-22T16:48:37Z")

</div>

If this template helps then use it. If not then just delete and start from scratch.

**OS** (e.g. Win10): OS X 10.14.6  
**PsychoPy version** (e.g. 1.84.x): 3.1.5

My question is about how to best time sounds in Builder. Having read the documentation, I thought I would use the PTB sound device, but I can see that this is not listed in the preferences.  
So I added it there, and that throws an error

ValueError: audioLib pref should be one of [‘sounddevice’, ‘pyo’, ‘pysoundcard’, ‘pygame’], not ‘PTB’

I also tried to set this in a custom code component at the start of the experiment:  
prefs.hardware[‘audioLib’] = [‘PTB’]  
from psychopy import sound

That does NOT throw an error, but when I then use the code adapted from the documentation

```
sound_2.play(when = now+interval)

```

I get the following error:

TypeError: play() got an unexpected keyword argument ‘when’

Some more research revealed that this is probably because sound device is  
\<class ‘psychopy.sound.backend\_sounddevice.SoundDeviceSound’\>

Any tips on how to ensure decent sound timing, esp. when loading sound from files & using builder?  
THanks  
Marc

**What specifically went wrong when you tried that?:**  
Include pasted full error message if possible. “That didn’t work” is not enough information.

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [January 22, 2020, 9:17pm UTC](https://discourse.psychopy.org/t/sound-timing-question/10677/2 "2020-01-22T21:17:24Z")

</div>

Hi @Marc_Buehner, yes to get the best accuracy and precision, use the PTB library. In case you have not seen it yet, we have a preprint available to demonstrate what you can achieve with PsychoPys new PTB audio engine [see [The timing mega-study (2020)](https://discourse.psychopy.org/t/the-timing-mega-study-2020/10660)].

However, to use PTB you need to have a 64bit Python 3 - [see docs](https://www.psychopy.org/api/sound.html).
