Presenting pairs of auditory stimuli - second stimulus not appearing

Hello everyone,

I am trying to present a pair of beep sounds with an ISI of 1 second between them. The first beep appears every 6-10 seconds. How can I make the second beep come up 1 second after the first one? I’ve tried so many things but haven’t been able to. I am attaching code below which excludes my failed attempts to present the 2nd stimulus.

#loads the sound file and plays sound for 0.1 seconds
tactors1 = sound.Sound('test_100_200Hz.wav', name='$tactors1', stereo = True, secs = 0.1)
tactors1.setVolume(1)
tactors1.playing = False
tactors1.waiting = False


tactors2 = sound.Sound('test_100_200Hz.wav', name='$tactors2', stereo = True, secs = 0.1)
tactors2.setVolume(1)
tactors2.playing = False
tactors2.waiting = False

tactors1Onsets=[]
tactors1ISIs=[]

tactors2Onsets=[]
tactors2ISIs=[]


# we want to present the tone every
# 6 - 10 seconds for the duration of the trial
# if the sound is not currently playing
if not tactors1.playing and not tactors1.waiting:
    # pick how long we will wait for
    tactors1ISI = randint(6, 10)
    print('tactorISI', tactors1ISI)
    tactors1ISIs.append(tactors1ISI)
    tactors1Onset = t +tactors1ISI
    #we are waiting for the sound to play
    tactors1.waiting = True
elif not tactors1.playing and tactors1.waiting:
    if t >= tactors1Onset:
        print('playing')
        tactors1.play()
        tactors1Onsets.append(t)
        tactors1.playing = True
        tactors1.waiting = False
                
elif tactors1.playing:
    if t >= tactors1Onset + tactors1.secs:
        tactors1.stop()
        tactors1.playing = False

How can i initiate the second beep (tactors2) 1 second after the tactors1 finishes?

Would greatly appreciate any help with this…

bump!

Hello! Couple of things:

  1. Is this following on from this study?
  2. Is there a reason you cannot use a single sound file that contains both tones?
  3. If you know the onset and duration of the sound the following should do the trick:

Begin Routine:

tone.playing = False
interval = 1#desired interval in seconds
if t >= toneOffset + interval and not tone.playing:# where offset if your known offset time and t is the ongoing time in this routine
    tone.playing = True
    tone.play()

That looks pretty similar to what you have tried though? Perhaps you could please share the file you are working ok?

Thanks!
Becca

Hello Becca,

  1. Yes, but the experiment direction has completely changed!

  2. I can’t do because this sound turns on this tactor device that we have that creates a vibration

I JUST managed to get the second beep to work with the following code.

# we want to present the tone every
# 6 - 10 seconds for the duration of the trial
# if the sound is not currently playing
if not tactors1.playing and not tactors1.waiting:
    # pick how long we will wait for
    tactors1ISI = randint(6, 10)
    print('tactorISI', tactors1ISI)
    tactors1ISIs.append(tactors1ISI)
    tactors1Onset = t +tactors1ISI
    #we are waiting for the sound to play
    tactors1.waiting = True
elif not tactors1.playing and tactors1.waiting:
    if t >= tactors1Onset:
        print('playing 1st tactor')
        first_tactor_played = False
        tactors1.play()
        tactors1Onsets.append(t)
        tactors1.playing = True
        tactors1.waiting = False
        tactor1_on_times +1
        first_tactor_start_time = core.getTime() # Gets a timestamp of the start of the first vibration       
        first_tactor_played = True
elif tactors1.playing:
    if t >= tactors1Onset + tactors1.secs:
        tactors1.stop()
        tactors1.playing = False
        first_tactor_played = True
        first_tactor_stop_time = core.getTime()

#2nd vibration

if not tactors2.playing and not tactors2.waiting:
    if first_tactor_played == True:
        # pick how long we will wait for
        tactors2ISI = 1
        print('tactor2ISI', tactors2ISI)
        tactors2ISIs.append(tactors2ISI)
        tactors2Onset = t +tactors2ISI
        #we are waiting for the sound to play
        tactors2.waiting = True
elif not tactors2.playing and tactors2.waiting:
    if first_tactor_played == True:
        if t >= tactors2Onset:
            print('playing 2nd tactor')
            tactors2.play()
            tactors2Onsets.append(t)
            tactors2.playing = True
            tactors2.waiting = False
            tactor2_on_times +1
        #first_tactor_start_time = core.getTime() # Gets a timestamp of the start of the first vibration
                
elif tactors2.playing:
    if t >= tactors2Onset + tactors2.secs:
        if first_tactor_played == True:
            tactors2.stop()
            tactors2.playing = False
            first_tactor_played = False
1 Like