psychopy.org | Reference | Downloads | Github

Variable duration in sounds and error message for wrong key


#1

Hi everyone!
I use Psychopy 1.84.2 on a PC with builder mode.
Currently, I am building a lexical decision task with sound files and everything runs fine. But I would like to include two things:
First, I have a problem setting the allowed response time for the stimuli. Each sound file varies in length, and I want to set the possible response time for 4s after the offset of each stimulus. I read that with a combination of sound_1.status == FINISHED for the start condition and get.Duration() for the end condition, but am not sure how to set it up.
The second problem is that I have set the key response for two allowed keys (in a Cedrus button box) and I want to include a message in case the participant hits a wrong key. This should not be feedback, but simply remind him/her to only press one of the allowed buttons. I found the option for feedback in the Psychopy library (Stroop extended task), but don’t know how to adapt it for simple feedback that is not connected to right/wrong answers.
Thank you so much for your help!
Nora


#2

Something like sound_1.getDuration() for the start time and sound_1.getDuration() + 4.0 for the end time, assuming your sound starts playing at t=0. Alternatively, rather than an end time, you could simply specify a duration of 4.0

Make sure that the sound component is above the keyboard component: that way the code for the sound is executed first, so the keyboard code is able to refer to the current duration of the sound file. i.e. it presumably gets updated each trial: if the keyboard comes first, it will be trying to access the duration of s sound file that hasn’t been loaded yet.


#3

Hi Michael,
Thank you so much! That was it!! Do you also happen to know how I can change the code for the message from this:

if not key_resp.keys :
    msg="Failed to respond"
elif resp.corr:#stored on last run routine
    msg="Correct! RT=%.3f" %(resp.rt)
else:
    msg="Oops! That was wrong"

so that I don’t get feedback on the correct or incorrect answer, but instead simply a message if the participant hit the wrong key. So far, I inserted:

if not key_resp.keys :
    msg="Failed to respond"
elif resp.corr and resp.incorr: #stored on last run routine
    msg==0
else:
    msg="Oops! Wrong key"

but nothing happens. I also included the msg definition at the beginning of the experiment. Thank you!!


#4

I could suggest changes to that code but it’s not clear what it would be fixing. i.e. “nothing happens” is not a useable description of a problem.


#5

Hi Michael,
Sorry about that. What I meant was that the experiment runs without a problem, but none of the messages show up. I would like to only have a message pop up if and only if the participant hits a different key than the two allowed ones, or if the time limit runs out. Please let me know if I should post anything else to help clarify the problem.
Thank you!
Nora


#6

The code should probably look like this:

if not key_resp.keys :
    msg = "Failed to respond"
elif ! resp.corr:
    msg = "Oops! Wrong key"

But the effect it has depends on where this code is placed (i.e. which routine, and which tab of the code component), and the settings of the text field.

I would suggest putting this code in the End routine tab of a code component of the routine that holds the response component. In the text component (presumably on the next routine?), make sure the text field is set to update every repeat, so it gets the updated value of $msg.