Sound component crashing - SoundPygame object has no attribute 'seek'

Win11
PsychoPy version 2024.1.5
Standard Standalone

Hi there,

I am trying to create a “correct ding” and “incorrect buzz” feedback response for a basic Eriksen flanker task.

I have created my flanker loop (see image below).

In my feedback routine within this loop I have sound components correctding_p (600 Hz for 0.2 seconds) and incorrectbuzz_p (300 Hz for 0.2 seconds). The feedback code is as follows:

if keys_trials_response.keys == str(correct_response):
thisExp.addData(‘accuracy’, 1) # Store 1 for correct response
correctding_p.play() # Play high tone for correct response
incorrectbuzz_p.stop() # Ensure incorrect sound is not played
else:
thisExp.addData(‘accuracy’, 0) # Store 0 for incorrect response
incorrectbuzz_p.play() # Play low tone for incorrect response
correctding_p.stop() # Ensure correct sound is not played

When I run the experiment it works and plays the ding, but then immediately crashes with this error:

AttributeError: ‘SoundPygame’ object has no attribute ‘seek’

I have tried different versions of this code, and nothing seems to work. I have also changed audio libraries, but that doesn’t fix the issue. As an aside, I am using pygame (as this is the only audio library that will play a sound when I use this code).

Does anyone have any tips please?

Much appreciated!

Hello Alex

I have a little toy experiment that plays a low tone for a wrong answer and a high tone for a correct answer. It also stores the correctness of the answer in the result file. To store the correctness of the answer in your result file, you need to define a column in your stimulus file that defines the correctness of the answer. You can use this variable to set the feedback tone. You will need to define the correctness variable in the Builder, see below.

feedSound.psyexp (15.2 KB)
feedSound.xlsx (9.6 KB)

Best wishes Jens

Thanks very much Jens!

My code worked in the end (copied below in case anyone else needs it in future). I needed to use this code rather than ticking the correct answer in the box as one of my routines uses a mouse response in a location.

Interestingly I found the sound was distorted when playing it on my local computer but when I play as an online experiment the different tones sound okay - so that is a relief!

Initialize accuracy
accuracy = 0

Get the keyboard response

response_keys = keys_trials_response.keys

Check if the response is ‘4’

if response_keys == ‘4’:
if correct_response == ‘R1’: # Check if the correct response is R1
accuracy = 1
# Play correct sound
correct_ding_2.play()
else:
# Play incorrect sound
incorrect_buzz_2.play()

Check if the response is ‘6’

elif response_keys == ‘R2’:
if correct_response == ‘6’: # Check if the correct response is R2
accuracy = 1
# Play correct sound
correct_ding_2.play()
else:
# Play incorrect sound
incorrect_buzz_2.play()

Store the correctness of the response in the experiment handler

thisExp.addData(‘accuracy’, accuracy)

Hello

Well, you are still checking the keyboard and not the mouse in code, so in principle key_resp.corr should work. Anyway, you found a solution that works for you.

You might want to tell us when you added your code: Begin experiment, Begin routine aso.

Best wishes Jens

Thank you! Yes sorry I was a bit vague there - the experiment has one version for keyboard responses and one for mouse responses. I used the same code for both rather than use the key_resp.corr funciton - but I appreciate the tips!