How to repeat sound with a "R" key

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

OS (e.g. Win10): win11
PsychoPy version (e.g. 1.84.x): 2022.2.5
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:

I am trying to build a routine with a loop, participants will see a picture and hear a sound at the same time, after the sound over, they should give a rating of the picture. There are 10 different pictures and 10 different sound, one match one. Besides, before they give rating, they can choose to repeat the sound by pressing key “R”.

What did you try to make it work?:

I look at this page: Replay stimulus multiple times in PsychoPy - Stack Overflow
and try to add a component to make it work, but it didn’t.
I think the main problem was that how could I set the sound in code component, the sound should match the randomly show up picture in the excel list.

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

ValueError: setSound: could not find a sound file named A03_audio.wav

Why do you use a code component? Don’t you have a spreadsheet with the matching stimulus?
Can you declare the audio path and images in the spreadsheet and call them from each component?


Hello Chen,

Thanks for your reply.
I do have a spreadsheet with the matching stimulus, but if I use “sound” component, the sound can only be played once. I want the participants can hear again or more times only if they press a special key.

The answer of the above linked page Replay stimulus multiple times in PsychoPy - Stack Overflow said that it can be achieved by a code component, and I use, but there is still some problem…


here is a solution using a mouse-component in the end. But a keyboard-component would work in the same manner.

Best wishes Jens


I have fixed it, thanks for you help!