View Single Post
  #2  
Old 02-02-2016, 02:18 AM
Erikvdb Erikvdb is offline
Member
 
Join Date: May 2013
Posts: 63
Here you go, I also included the random wait

Code:
import viz
import viztask
import random

viz.go()

sound = viz.addAudio('pip.wav')
soundDuration = sound.getDuration()

def playSoundLoop():
    count = 0
    while count < 10:
        count += 1
        sound.play()
        yield viztask.waitTime(soundDuration+random.randrange(1,4))
        sound.stop()
		
viztask.schedule(playSoundLoop)
Couple of notes:
soundDuration is the duration of the sound you want to play. I use that as the minimal waitTime, to make sure Vizard won't attempt to play the sound again before the first one has finished.
I say attempt, because Vizard won't play the sound from the start if that same sound object is still playing. This was the problem in your code.
This is also why I included the sound.stop() at the end, to make 100% sure the sound is stopped before we try to play it again.
The random.randrange() is the random time after the sound has played for Vizard to wait until the next sound, in this example it'll be between 1 and 4 seconds.
Reply With Quote