PDA

View Full Version : Scheduling action at different timings using time.time()


jelly
05-16-2016, 07:25 AM
Hello!


I am trying to schedule an action (a beep sound) in Vizard. However, I want the beep to happen at certain timings since onset of the trial.

What I have so far gives me (for example, after running it once) a list of times "times: [ 1.89229142 5.2610474 9.86058804 11.43137033 13.87078666]" and is playing the beep at what seems to be varying intervals and prints out the elements of the above mentioned list. It's just that it's not actually using these elements as seconds/timings at which to play.

My question is: How do I make Python know that these are not just numbers, but timings since onset of the function/trial? Probably I am supposed to use time.time() somewhere, but I am just not sure about the logic of how to get there.

import time
import numpy as np
import viztask


### Start Vizard ###
viz.go()


### Cue sound ###
cue = viz.addAudio('cues\dong.wav')
cueDuration = cue.getDuration()

### Timings ###

def uniform_min_range(a, b, n, min_dist):
while True:
times = np.random.uniform(a, b, size=n)
np.sort(times)
if np.all(np.diff(times) >= min_dist):
return times

def timings():
global times
times = uniform_min_range(0, 20, 5, 1.0)
print "times: ", times


def main():
global times
timesIndex =0
for x in range(len(times)):
cuetime = times[timesIndex]
cue.play()
print 'cue'
print cuetime
yield viztask.waitTime(cueDuration + cuetime)
cue.stop()
timesIndex = timesIndex + 1



timings_short()
viztask.schedule(main())

Jeff
05-20-2016, 03:19 AM
You can use the viz.tick (http://docs.worldviz.com/vizard/#commands/viz/tick.htm) command to get the time since the script has started.