Presenting an audio sound with certain stimuli but not others

Hi, I’m hoping someone can help me understand the best way to implement this as I’m a beginner to coding and struggling to figure this out. Is it possible to do the below using a coding element in builder?

What are you trying to achieve?:

I have an experiment with 4 visual stimuli (let’s say a square, circle, triangle and star).

In block 1: 2 of these stimuli (square and circle) will each be presented in random order 20 times, with an ITI break between each one.

In block 2: the other 2 stimuli (triangle and star) will be presented in random order 20 times with an ITI break between each one.

I have generated this aspect of the experiment using a loop for the blocks and a nested loop for the stimuli, and it runs as expected.

However, additionally, an audio sound should be paired with 1 of the 2 stimuli in each blocks.

So in block 1: the square should be paired with a sound, but the circle should not. Similarly, in block 2: the triangle should be paired with a sound, the star should not.

However, for the square and the triangle stimuli that have been paired with the sound, the audio sound should only play for 60% of the times when those visual cues are presented. In this experiment, because each stimuli is shown 20 times, that would mean 12 of the times the square or triangle are presented, the sound is played, but 8 of the times it isn’t. This should be randomised, but with some constraints outlined below.

In each block:

  • The first stimuli must always be the one with NO sound (i.e. the circle in block 1, and the star in block 2)
  • For the visual stimuli that are associated with a sound 60% of the time (i.e. the square in block 1 and the triangle in block 2), the first and last time each of these are visual cues are presented in the block must be one of the times the sound is played. So 2 of the 12 times (out of the 60% of 20 trials).

So the sequence would be

Block 1

  • 1st stimuli: Square (no sound)
  • 2nd stimuli: Circle (sound: on)
  • [random sequence of square (no sound) and circle (with sound on 60% and sound off (40%))]
  • Last stimuli: circle (sound: on)

Block 1

  • 1st stimuli: Triangle (no sound)
  • 2nd stimuli: Star (sound: on)
  • [random sequence of Triangle (no sound) and Star (with sound on 60% and sound off (40%))]
  • Last stimuli: Star (sound: on)

I hope that makes sense!

Hey - just wondered if you ever managed to find a solution for this? I’m also fairly new to programming but I have created experiments with PsychoPy previously, however they were simple stroop task variations.

I’m now beginning to program my dissertation project, for which I would prefer to use PsychoPy but adding the sound stimuli seems to be more complex than I had imagined.

For mixed trial types I use a short silent sound stimulus when not presenting sounds (and a transparent png when not presenting images).

silence.wav

transparent.png

Thank you for your response.

I’m intending for a 1 second tone to be played every 4 or 5 seconds whilst the trials run. This is for all trials, irrespective of the visual stimuli. I will have play around now, but would you suggest adding the silence.wav file between each 1 second tone?

I would create a sound file for the tone, set it up before the trials loop in a sound component (e.g. called myTone with volume 0) and then use something like this in your loop

Begin Experiment

myClock = core.Clock()

End Routine (last trial before loop)

myClock.reset()
nextTone = 4 + random()
myTone.setVolume(1)

Each Frame

if myClock.getTime() > nextTone:
     nextTone += 4 + random()
     myTone.play()

Amazing, thank you!

Just to clarify, I assume that this fix cannot be implemented using Builder, it would require coding instead?

I exclusively use Builder for experiments, and add code in code components (which have tabs Before Experiment, Begin Experiment, Begin Routine, etc)