psychopy.org | Reference | Downloads | Github

Sound feedback after a key response

Hi guys,

I’m trying to conduct the stroop test and I want to include a buzz whenever the participant makes a mistake. I went through YouTube videos and some of the posts about the same topic and I tried to mimic the procedure. However, whenever the experiment starts and when it’s supposed to give a noise it crashes.

I’m attaching snippets from the experiment, the code and the error that I got. Just as a note in the code you’ll find the “a” variable, it’s just a dummy variable to fill in the if statement.

Your help is much appreciated.
Thank you in advance.

Use something like Audacity to convert your sound file to 44.1 kHz rather than its current 48 kHz.

Hi,

Thank you for reply. It worked. However, now, whether the keyboard response is correct or not the buzz sound will play. Do you have any idea why is this happening?

Hello Moe,

you don’t need an if…else construction, if you don’t use the else-part.

if not key_resp_4.corr:
    buzz = soundfile[0]

should do the work. The reason that the sound is always played means that the if…else construction always evalutes to the else-part.

When you want to play the sound after the participants has reacted you have to move the code-element from the Begin Routine tab to the End Routine tab.

Best Jens

Hello,

Thanks for your reply. I removed the else part and shifted the code from the “Begin Routine” to the “End Routine” tab. When I run the experiment, the following error occurs.

File “C:\Users\Other user\Desktop\Noise Experiment\Noise Experiment_1_lastrun.py”, line 387, in
sound_1.setSound(buzz, hamming=True)
NameError: name ‘buzz’ is not defined

Experiment ended.

The “buzz” is defined in the sound component shown in the figure below.
I tried to move the sound component above the code component (maybe it was an order problem) but the same error occurred.

Any ideas?

Hello,

did you ever define the variable buzz somewhere before you use it for the first time, e.g. in the tab Begin experiment? The code-element should appear before the sound-element.

Best Jens

Hi
I am stock in the same problem.
how can i define the vairable buzz? i know how to define a massege. e.g :msg=" "
but how to define a sound?
i tried
soundfile = “incorrectBUZZER.wav”

Hello

This defines a variable soundfile with the content incorrectBUZZER.wav.

Best Jens

1 Like

Hello,

here a small example which plays a sound when inccorrect and no sound when correct. I simply set the loudness to 0 when the response is correct while defining the same sound file for correct and incorrect answers.

SoundFeedback.psyexp (12.4 KB) Stimuli.xlsx (8.4 KB)

Best Jens

Hello,

as a matter of fact the code could be even simpler. You only need to set the loudness in your if…else construction. You do not have to set your feedback-file in the if…else construction.

Begin Experiment tab

msg = " "
soundFeedBack = 'CriticalStop.wav'
loudness = 1

Begin Routine tab

if key_resp.corr:
    msg = "correct"
    msgcolor = "green"
    loudness = 0
else:
    msg = "incorrect"
    msgcolor = "red"
    loudness = 1

Best wishes Jens

1 Like

Thank you! i actually did that and it worked :slight_smile:

@chayabenyehuda

Do you mind marking it as solution? Then it is found more easily.

Best Jens