I’m new to psychopy and trying to build an experiment. In this we want the participants to press a key when they see the target slide and when they press the key they should hear a sound in the form of feedback so that they know they pressed the key.
We want to add sound to pressing a specific key - without ending the trial participants should continue the experiment and be able to press that key whenever they see the targeted slide and should hear a sound on pressing the key in the form of feedback.
Is there any way of adding sound on key press without using code? can anyone help please?
You can change the frequency (1245), duration (0.2 s), and volume (0.8) that are set here. Then in a code component within your trial on the Every Frame tab, wait for a left keypress (or change to whatever you want) and play the sound for the desired duration (0.2).
if 'left' in key_resp.keys and not correct_started:
correct_started = True
correct_start_time = globalClock.getTime()
if correct_started and not correct_ended:
if globalClock.getTime() - correct_start_time >= 0.2:
correct_ended = True
correct_started = False
This will make sure the sound only plays for the desired time, here 0.2 s. You’ll also need to initialize the correct_started and correct_ended variables in a Begin Routine tab