auto-repeat the audio stimulus within the same trial
in OpenSesame
Hello.
In a loop we need to administer an audio stimulus (a musical phrase) together with different images. The subject is asked to associate one image to the music.
According to the protocol the musical phrase should be presented continuosly, id est in loop, till the subject's response.
Is it possible ?
Thank You for your attention and MANY THANKS to the developers of OpenSesame,
Dan
Comments
Hi Dan,
That is possible, but requires using python inline coding (I don't think the Sampler GUI item, has a repeat setting).
What you would want to do, is creating a while loop that tracks the progression of time, and starts the sampler every time the duration of the sample has passed. Additionally, this loop check whether a response has been given and breaks the loop once this happens. More info here: https://osdoc.cogsci.nl/3.3/manual/python/sampler/
And here a skeleton example:
# load sample src = pool['bark.ogg'] my_sampler = Sampler(src, volume=.5) # create a keyboard my_kb = Keyboard(timeout = 0) start_time = clock.time() # how long is the sample? sample_duration = 1000 # loop until a key is pressed # <add some code to present your images> my_sampler.play() while True: # check if sample duration has been passed and restart if start_time-clock.time()> sample_duration: my_sampler.play() start_time = clock.time() # check for a keyboard response k,t = my_kb.get_key() if k != None: breakI hope this helps,
Eduard
Thank You Eduard for your attention and your patience.
OpenSesame stops while compiling the script:
File "C:\Program Files (x86)\OpenSesame\Lib\site-packages\libopensesame\inline_script.py", line 81, in prepare self.var.get(u'_run', _eval=False)) File "C:\Program Files (x86)\OpenSesame\Lib\site-packages\libopensesame\base_python_workspace.py", line 110, in _compile return compile(script, u'<string>', u'exec') Inline script, line 18 k,t = my_kb.get_key() ^ IndentationError: unindent does not match any outer indentation levelHi Dan,
I typed this example in the window here, so the formatting cannot be trusted. The error is quite clear actually. It says
IndentationErrorso you should check whether the indentation level checks out. Are you familiar with Python syntax? If not have a look here: https://osdoc.cogsci.nl/3.3/manual/python/about/ (particularly the tutorials). In short, in Python the indentation level is critical to parse the code into blocks. Indentation level is basically defined by how many white space (space bar) characters appear in the beginning of the line. For each code block (for-loop, if-else statement, etc) the number of white space has to match.What the problem in your specific case is, I cannot say without seeing how you included the code into your experiment. If you share your experiment, I can help better.
Eduard
Thank you Eduard,
again, I learned a new thing: indentation is not just a matter of aesthetics.
Yes sure, may I share the whole file here ?
Dan
Yes, you can!
Voilà, I attach two files
thank you Eduard :-)
Hi,
I added the new version that includes the basic working example. The fine-tuning is left, but I am sure you can handle it. When you use the inline_script, it make sense to run the response collection and stimulus presentation also with it. Therefore you probably want to remove the keyboard_response item and (some of) the sketchpads. But see for yourself what makes sense.
Good luck,
Eduard
Thank you Eduard,
I am experimenting by consequence of the file you sent me and of https://osdoc.cogsci.nl/3.3/manual/python/about/
Musically,
Danilo