View Single Post
  #3  
Old 02-19-2008, 02:26 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Don't worry, we haven't forgot about you. Yesterday was a holiday.

Here is sample code that will update a progress bar while a speech action is running. It works by starting a timer when the speech begins. The timer uses the action instance to determine the current time of the speech.
Code:
import viz
viz.go()

#Create avatar
avatar = viz.add('female.cfg',pos=(0,0,1),euler=(180,0,0))

#Create speech action
speak = vizact.speak('speech.wav',sync=True)

#Create progress bar
progress = viz.addProgressBar('',pos=(0.5,0.1,0))

#Function that will update progress of speech while it is running
def updateSpeechProgress(progress,instance):
	progress.set( instance.elapsed / instance.length )

#Start update timer when speech action begins
def onActionBegin(e):
	if e.object is avatar and e.action is speak:
		avatar.speechProgress = vizact.ontimer(0,updateSpeechProgress,progress,e.instance)
viz.callback(viz.ACTION_BEGIN_EVENT,onActionBegin)

#Stop update timer when speech action ends
def onActionEnd(e):
	if e.object is avatar and e.action is speak:
		vizact.removeEvent(avatar.speechProgress)
viz.callback(viz.ACTION_END_EVENT,onActionEnd)

#Start speech when spacebar pressed
vizact.onkeydown(' ',avatar.runAction,speak)
Reply With Quote