# Sounds problems

**URL:** <https://discourse.psychopy.org/t/sounds-problems/9123>\
**Category:** Coding\
**Created:** [September 21, 2019, 3:18am UTC](https://discourse.psychopy.org/t/sounds-problems/9123 "2019-09-21T03:18:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![glupyan](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@glupyan](https://discourse.psychopy.org/u/glupyan)\
**Post date:** [September 21, 2019, 3:18am UTC](https://discourse.psychopy.org/t/sounds-problems/9123/1 "2019-09-21T03:18:16Z")

</div>

Hey everyone, finally updated to the latest PsychoPy library. Excited about the new low latency sound. After upgrading sounds only play once. This is true for PTB, pyo, sounddevice… What’s happening? 😮

Minimal example:

```auto
import psychtoolbox as ptb
from psychopy import prefs
print(prefs.general)
prefs.general['audioLib'] = 'PTB'
from psychopy import sound, visual, event

mySound = sound.Sound('A', secs=0.1)

win = visual.Window([300,200],color="black", units='pix')
win.flip()

while True:
	if event.getKeys(keyList=['t']):
		print('playing sound')
		mySound.play()

```

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [September 21, 2019, 9:40pm UTC](https://discourse.psychopy.org/t/sounds-problems/9123/2 "2019-09-21T21:40:17Z")

</div>

What happens if you shift the `win.flip()` to inside the `while` loop (but outside the `if` block)?

---

<div class="post-metadata">

**Author:** ![glupyan](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@glupyan](https://discourse.psychopy.org/u/glupyan)\
**Post date:** [September 22, 2019, 3:29am UTC](https://discourse.psychopy.org/t/sounds-problems/9123/3 "2019-09-22T03:29:34Z")

</div>

Did some more digging around. Turns out that the command for setting audioLib that used to work, e.g.,

```auto
prefs.general['audioLib'] = ['pyo']

```

now does not… it needs to be

```auto
prefs.hardware['audioLib'] = ['PTB']

```

So in my example above, the sound was being played via the default `sounddevice`. When I switch it to `PTB`, the problem goes away. The problem with the sound only being played once persists, but is limited to `sounddevice`

---

<div class="post-metadata">

**Author:** ![glupyan](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@glupyan](https://discourse.psychopy.org/u/glupyan)\
**Post date:** [September 22, 2019, 3:36am UTC](https://discourse.psychopy.org/t/sounds-problems/9123/4 "2019-09-22T03:36:27Z")

</div>

> [@glupyan](#):
>
> import psychtoolbox as ptb from psychopy import prefs print(prefs.general) prefs.general[‘audioLib’] = ‘PTB’ from psychopy import sound, visual, event mySound = sound.Sound(‘A’, secs=0.1) win = visual.Window([300,200],color=“black”, units=‘pix’) win.flip() while True: if event.getKeys(keyList=[‘t’]): print(‘playing sound’) mySound.play()

Thanks. Doesn’t help though. Seems like a sounddevice issue (see above)
