psychopy.org | Reference | Downloads | Github

Backend sound device issue in 3.1.2, unsupported operand type

OS (e.g. Win10): macOS Mojave 10.14.5
PsychoPy version (e.g. 1.84.x): 3.1.2
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: using a mouse click to replay a sound

What did you try to make it work?: code snippet and mouse component
if mouse1.isPressedIn(image):
.... rate_sound.play()

What specifically went wrong when you tried that?: The sound replays but is horribly distorted, then no sound in the following trials plays audibly. Once I press esc I see the following error:

Any ideas how to fix this?

Hi @fetch, I think the problem is that after your isPressedIn if statement becomes true, you are calling the sound.play() method every screen refresh. Instead, you may want an additional check to make sure the sound is not already playing. E.g.,

# Begin routine
soundPlaying = False

# Each Frame
if mouse.isPressedIn(image) and not soundPlaying:
    soundPlaying = True
    rate_sound.play()

Thank you so much, your suggestion worked perfectly. I appreciate the help! :partying_face: