Metronome - repeat a sound throughout the experiment
Hi!
I have the following task: the subjects have to identify the number of points in a set. Each set stays on screen until they press a key.
I need a sound to play in the background every one second (a click sound for example) until the task is completed (40 sets of points in total).
So far I've managed to make the sound play once with each set by placing a sampler inside the inline_script where I created the stimuli, or for the sound to be repeated throughout the task with a clock.loop_for () in an inline_script outside the loop but i cannot control the ms between each sound. In addition, i used clock.loop_for(50000) to cover the whole task and the experiment crashes.
I'm guessing this is something simple to do, but I've tried every tutorial I could find an I'm not getting anywhere. Sorry for my English. If someone can give me a hand I would be very grateful.
Comments
Hi,
I recommend to predefine the sets of dots (your 40 trials), that is, preparing lists with stimulus position, etc. Maybe even prepare the 40 canvasses in advance. Once you done that, you can (in an inline_script) make a while loop that runs forever. In this while loop you keep track of the time and present a click every time a second has passed. Also in the same while loop, you add a phase in which you present a stimulus (if there was a keypress), and one in which you sample for keypresses. Does that make sense? I'll put a conceptual example below:
# prepare sampler ## load the sound files and prepare the sampler # prepare canvasses ## draw the canvasses with the dots and save the canvasses in a list #make a keyboard item kb = Keyboard() #start timer t0= canvas_list.pop(0).show() while True: if clock.time()-t0>1000: sampler.play() t0= clock.time() k,t = kb.get_key() if k != None: if len(canvas_list) == 0: break else: canvas_list.pop(0).show()Does that make sense?
Eduard
Hi Eduard,
Thanks a lot for the quick response. I get the general idea but I do not have list of canvasses, just a list of groups of dots
When i try to use list.pop(0).show() with my list (circulos.pop(0).show()) instead of a canvasses list, it tells me that a 'str' object has no attribute 'show'. Do you know what I am doing wrong?
Tranks again for your help,
Jesi
Hi Jesi,
You have now a loop for the number of dots in a single trial. But what I meant is that you need a loop for the trials. So, if you wrap another loop around your for loop (loop as often as you have trials), then you will have a list of dot lists. This outer list is then what you can use to bring the trials one by one on the screen. Does that make more sense? Also, the function xy_random returns a list of dots. That means that when drawing them, you still have to loop over them, so something like:
for x,y in circulos: canvas.fixdot(x,y)or if you have the nested list:
for x,y in circulos[current_trial_index]: canvas.fixdot(x,y)Eduard
PS: If you share code, please post it as a text not as a screenshot. This will make it easier to edit it.
Hi Eduard,
Thank you very much!
Jesi
PS: I did not know that, sorry!