# Keypress during sound stimuli error linux

**URL:** <https://discourse.psychopy.org/t/keypress-during-sound-stimuli-error-linux/11079>\
**Category:** Coding\
**Tags:** sound\
**Created:** [February 19, 2020, 4:39pm UTC](https://discourse.psychopy.org/t/keypress-during-sound-stimuli-error-linux/11079 "2020-02-19T16:39:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![haleyk](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@haleyk](https://discourse.psychopy.org/u/haleyk)\
**Post date:** [February 19, 2020, 4:39pm UTC](https://discourse.psychopy.org/t/keypress-during-sound-stimuli-error-linux/11079/1 "2020-02-19T16:39:02Z")

</div>

hi all,  
I have a task where a sound is played (psychopy.sound.Sound) and participants need to respond by using the keyboard whether the sound is a match or not. This task works fine on multiple Macs. However, on my linux machine when participants press a key while the sound is still playing, a ‘bad’ noise is produced on top of the sound (sounds like an error noise, although I don’t know exactly how to describe it). I have tried using different sound backends (pyo + ptb) but the sound remains.

The error printed to the terminal is `ALSA lib pcm.c:8306:(snd_pcm_recover) underrun occurred` and it prints this many many times (while key is held down). I have searched this on it’s own with no discernible solutions.  
I’ve read a bit [here](https://discourse.psychopy.org/t/a-word-about-pyo-audio-backend/2253) but didn’t seem to find the answer. I assume it has something to do with the threading/refresh rate as I don’t get this error on other OS’s. Code below reproduces the error on my linux machine (but not my mac) if you press a key while the sound is still playing.  
Thanks for any insight!

```auto
from psychopy import visual, monitors
from psychopy.visual import Window
from psychopy import core, event
from psychopy.sound import Sound

win = visual.Window([600,400], color='black', fullscr=0)
no_response = True
s = Sound(value=300, secs=2.0, volume=.03)
win.flip()
s.play()
timer = core.CountdownTimer(2)
while timee > 0 and no_response:
	timee = timer.getTime()
	for key in event.getKeys():
		if key in ['1', '2']:
			no_response = False
win.flip()
win.close()
core.quit()

```

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [February 20, 2020, 10:13am UTC](https://discourse.psychopy.org/t/keypress-during-sound-stimuli-error-linux/11079/2 "2020-02-20T10:13:35Z")

</div>

What sound library have you set PsychoPy to use (in prefs)?

---

<div class="post-metadata">

**Author:** ![haleyk](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@haleyk](https://discourse.psychopy.org/u/haleyk)\
**Post date:** [February 20, 2020, 7:32pm UTC](https://discourse.psychopy.org/t/keypress-during-sound-stimuli-error-linux/11079/3 "2020-02-20T19:32:47Z")

</div>

right now it returns [‘sounddevice’, ‘PTB’, ‘pyo’, ‘pygame’], the audioDriver is [‘portaudio’], and the latency mode is 3.

---

<div class="post-metadata">

**Author:** ![haleyk](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@haleyk](https://discourse.psychopy.org/u/haleyk)\
**Post date:** [February 20, 2020, 7:41pm UTC](https://discourse.psychopy.org/t/keypress-during-sound-stimuli-error-linux/11079/4 "2020-02-20T19:41:18Z")

</div>

changing the backend to ‘PTB’ fixed the problem and stopped the error messages. I had previously done `Sound.backend_ptb.SoundPTB()` which I thought would have the same result, but apparently not. Thank you so much for pointing to the right place!
