Repeat the last sound file in sound component in a routine

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

OS (e.g. Win10): macOS Sonoma 14.3
PsychoPy version (e.g. 1.84.x): 2024.1.4 and 2023
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?:
I have a sound component consisting of 20 files. Each time the participant listens to a sound, they can press the mouse to go to the next one. However, I want to add the option of repetition (‘r’), so that they can repeat the last sound file they heard if they want before moving on to the next one."
What did you try to make it work?:
I tried adding extra loop for repetition , an


d I tried few attempts by coding, but it wasn’t successful, so any help is appreciated
What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

Hello again , does anyone have any suggestion how to do it ?
thanks in advance?

If you want to repeat a loop called repetition unless key_resp.keys == ‘r’ then try the following in End Routine

if key_resp.keys != 'r':
     repetition.finished = True

hello @wakecarter ,
I added to add a loop for repetition , but my main objective that I have 10 sounds to be played sequential , and I want to add an option of pressing (r) in order to repeat the last sound hear by participant , so for example if a participant heard sound (la) (ba) (mo) , he can have the ability to press (r) to repeat (mo) as much as possible , then he can press for example (C) to continue for next word

So a response of c (or not r) should break out of the inner loop but not the outer one.

lets suppose I have only one loop called repetition with excel file which contains 10 sounds to be played sequential , and as I mentioned r to repeat the last sound played , and c to continue for next sound , should I add another loop ? and where to add code?
thank you in advance !

image

The outer loop should point to the spreadsheet
The inner loop should not point to a spreadsheet but should have a large number of repetitions
Add a code component to Task3 and put the code in End Routine

for inner loop , I added number of rep to be 99,is this correct? what about an excel file or I should something else?
for code : only this code works ? or should I change something to add pressing “C” to continue for next sound,
and final question how it will know to play the last sound played? or it will repeat all sounds from start ??
thank you again!


You have just changed the name of the inner loop so the code won’t work any more.

Sorry to disturb you again ,
yes I changed the name in image just to make it simple for us to discuss it , so inner loop is rep. one ,
so what should I do next ?
thanks

What is the name of your keyboard response?

name of keyboard is : key_resp_1
name in code :key_resp.keys

if key_resp_1.keys == 'c':
     inner_loop.finished = True

I tried this , when I press c, it continue for next sound , but pressing (r) doesn’t do anything, this is the code I add

What are the allowed keys for key_resp_1 ?
Is it set to end the routine?

Try changing the start time of the audio component to 0.1 seconds

Also, try adding a short duration text component to confirm that the routine is repeating and that the problem is with the sound.

the allowed keys are :‘r’,‘c’
yes is set to end routine
I added 0.1 sec, and text , and if I press (c) it goes to next sound until it reached the third sound and the task crashes ,(pressing r at first or 2nd or third sound nothing happens)