WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Scheduling action at different timings using time.time() (https://forum.worldviz.com/showthread.php?t=5722)

jelly 05-16-2016 07:25 AM

Scheduling action at different timings using time.time()
 
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.

Code:

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 command to get the time since the script has started.


All times are GMT -7. The time now is 08:14 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC