I would like to present a 0.2s stimulus every 6-10 seconds for a total duration of 40 seconds (the duration of a video I am showing on screen).
Now I created the 6-10 seconds stimulus presentation randomiser by creating a code object and including the following code
interstimulus_interval_randomiser_audio = randint(low = 6, high = 10) # choose a value
thisExp.addData('interstimulus_interval_randomiser_audio', interstimulus_interval_randomiser_audio) # record it in the data file
I then call $interstimulus_interval_randomiser_audio at the start box of my auditory stimulus object. My question is how do I loop this stimulus presentation->randomised ISI (6-10s)->stimulus presentation->⌠for the duration of my video object (40 seconds video)
You are on the right lines for sure! What makes this a bit tricker is that you want a component to be presented multiple times within the same routine as a the video. So, there are 2 solutions:
add multiple sound components each with its own predetermined onset
do this in code (which I think is the approach you might prefer here!)
For solution 2, you would use the code you have but with a few more considerations. On each frame within the routine we want to detect a) is the tone currently being presented and b) are we currently waiting for a tone to be presented c) if neiter a nor b letâs pick an interval to wait then present the tone (and do this continuously whilst our trial is going on in the background.
Since there are a couple of bits of code here, here is a demo to help you on your way. A tone is presented every 3-5 seconds on a lop for the duration of a 10 second long trial.
Fantastic, thank you very much Becca for your help! Iâve now modified your code to the ISI and trial duration that is applicable to our experiment. Final question, what lines of code should I add for doing the exact same thing but with a picture stimulus?
For a picture, you would replace the initial creation of the sound component with an image (ImageStim â PsychoPy v2021.2) and replace instances of .play() with .draw() (you also wouldnât need things like .stop() for an imagestim.
Hope this helps!
Becca
PS. As you mention you are new to psychopy, heres something that might be useful. If you want to learn more about the code underlying a component or python in general. Make it in builder, then click compile to code then search the name of your image component in the coder window that opens! More details here Extending Builder with code â Workshops for PsychoPy 2020 2020
Thank you very much Becca for your help! Got everything to work as intended except for a new issue where the video Iâm playing is always infront of the image (brief distractor) Iâm trying to display. Any idea how to fix this?
Make sure your video is above your image in the components within the routine (right click > move up). If it isnât this itâs probably a different issue, so please could you mark the solution for this thread then start a new topic
I was able to use your code to present a text stimulus multiple times within the same routine as a video running for 30 seconds. However, I only want the text stimulus to appear twice randomly in the 30-second video sequence. Is there a way to change your code so the text-stim only appears randomly twice during the video sequence?
If you only want something to happen twice I would use a variable to count how many times something occurred and then present no more if that number is met.
your code has been hugely helpful to me when I needed use white noise to insert startle probes into my experiment. Thank you for this!
However, I need to include a second audiory stimulus (scream) that follows a different randomization and is supposed to play 1-3x during the routine while not overlapping with the startle sounds.
Right from the start when I try to modify the code to include the second sound in the âBegin Experimentâ tab, Psychopy creates the following error message:
The Javascript error Iâm not sure about because I canât see the JS code (what you are showing is just the python, please switch code type to âbothâ or âauto->jsâ to show the JS code), but my guess is that itâs the âimport timeâ line because that just doesnât exist in JS. However, w/r/t loading sound files into your program in JS, your best bet is actually to go to the experiment settings and go to the âonlineâ tab, and add them as assets. Pavlovia loads all external files once at the beginning, and if these are files which are not referred to in sound components, it probably wonât know they exist.
The python error, which will not occur when this study is run online, has to do with the fact that different sound files in your experiment have different sampling rates. Itâs a windows thing and itâs incredibly annoying. This says that something in your experiment is an audio file or tone with a sample rate of 11025Hz, and youâre trying to load an audio file with a sample rate of 44100Hz (which is much more standard). So youâll need to look at the files themselves and figure out their sample rates (for Windows I recommend Audacity, which is a free audio editing app), and convert them so they all have the same sample rate.
Thank you!
It appears that I was not fully understanding the content of the error message since I am rather new to psychopy and coding in python. I did not have âauto->jsâ selected because I am creating an experiment that will only be used offline so I was not too concerned with the javascript code.
That there could be a problem with the sound files on windows is a great hint! I will look into the mismatch in sample rates and correct it.