[open] Randomly presenting auditory stimuli with multiple variations
Hi all,
I am working on an experiment in which a participant will hear a carrier sentence (that has been manipulated in two different ways) followed by a target word. There are six different carrier sentences, but because we do not hypothesize an effect of different carrier sentences, a participant could be presented with any one of the six. The important thing is that they're exposed to two manipulations done to the sentence.
For example, our naming system for the files goes like this: "car1_ENV1_DUR1". The initial "carX" portion indicates which of the six carrier sentences it is, and the "ENVX" and "DURX" portion indicate the steps of the manipulations. Essentially, it does not matter whether a participant is presented with "car1_ENV1_DUR1" or "car5_ENV1_DUR1", as they are functionally the same in this experiment.
My question is, what is the best way to go about picking a random carrier sentence while still presenting the participant with equal amounts of the two manipulations?
Our idea right now is to use a MATLAB program to generate a list of stimuli with equal distributions of the "ENV" and "DUR" manipulation, but attached to random carrier sentences. Then we would import this list using a python code.
- Is this the best or easiest way to go about this?
- And if so, what would the coding look like?
I found this python code on the forum that I think we could use as a base:
path_list = exp.get_file("stimuli_list.txt")
import numpy as np
stimlist = np.loadtxt(path_list, dtype = str)
import random
random.shuffle(stimlist)
global stimlist
word = stimlist.pop()
exp.set("word", word)
If we did go about it using this method, I would also need to add a variable to the filename that reads the current subject number, so that it finds the list that corresponds to them.
I am very appreciative of your help!
Comments
Hi,
Well no, the best (maybe not best, but certainly easiest) way is to do everything in Python, that is Opensesame altogether.
For one, you need to define the variables that you want to manipulate in the
loop table
of aloop
item. For example, you could have two variables there:ENV
andDUR
and each of them contains all possible values. In thesequence
of thatloop
you can place aninline_script
, in which you can use plain python code. What you would need to do is creating the filename of the files that fit the values of your variables ENV and DUR. Something like that will do:As I understood, all the sentences and words are already saved somewhere in files. With the method I briefly described, you select which files contain the information that are needed for a particular trial, read this single file into Opensesame and its content during a trial. However, if this is not the case (e.g. everything is stored in one variable, or the sentences are freely cominable and currently not stored anywhere), you can also do the counterbalancing and randomization steps in the beginning of your experiment (from within an
inline_script
, which is basically python scripting). If you like to do that, let us know and we can give more info on how to do it.I hope this makes sense.
Good luck,
Eduard
Update: I've gotten part of it working, but now I'm stuck on how I take this filename I've generated and present the audio file it matches to. I know how to make the sample use variables from the Loop window, but I don't know how to take the filename from the python code and use it.
Hi,
It depends on the structure of your experiment (will you do everything in
inline_scripts
or are you only using them to prepare everything and then rely on other items likesketchpad
s andsampler
s).In python code is basically two things that you have to do:
1) Load the image :
sound = exp.pool['example.ogg']
2) Create the sampler:
my_sampler = sampler(sound, volume=.5)
(the third step would be to actually play the sound:
my_sampler.play()
)Does this make sense?
Good luck,
eduard
Thank you so much, I got that working!
I have ran into another issue: I'm trying to make an individualized sketchpad appear with response options depending upon the the word presented. There are six words, so I've created six sketchpads. The six words are: slab, lab, gab, clog, league, and tend.
Currently, I'm trying to do this by using a Python script that reads the filename (like "car1_ENV2_DUR3+sla_VL3.wav" and checks to see if any of the six words are in it. If it is present, I want it to change a variable to a different number, and then the appropriate sketchpad runs based on that variable's value.
This is what I have so far:
In the first sequence, I have a an inline script that sets the variable to zero:
Then in the experimental loop I have this:
Unfortunately, 'responseSP' doesn't seem to be changing as it prints "0" both before and after the series of "if" statements. I'm sure this is very easy to do, but I can't seem to get it to work.
Hi,
two things I'd like to point you to.
First, if you want to check whether something is true, you can't use the string
"true"
, but have to use it plainlytrue
(or simply1 or 0
).Second, if you test whether something is
in
something else, you don't to add atrue
comparison.So,
if 'lea' in file:
will be sufficient.Does this make sense?
Eduard