WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-15-2009, 10:39 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
What a fun tip.

I got a mouth-flapping avatar speaking via the API after some fiddling around.
Check it out:
Code:
import viz

viz.go()

#add the ground
viz.add('tut_ground.wrl')

woman = viz.add('vcc_female.cfg', pos = [0,.2,1], euler = [180,0,0])
woman.state(1)

import vizinfo
info = vizinfo.add('What should I say?')
info.scale([2,2])
textBox = info.add(viz.TEXTBOX)
textBox.setScale([2]*3)
textBox.overflow(viz.OVERFLOW_GROW)
textBox.message('I lovvvve yououououou')
speakButton = info.add(viz.BUTTON, 'Speak')

#used code from here: http://archives.seul.org/pygame/users/Jul-2008/msg00038.html
import win32com.client
tts4file = win32com.client.Dispatch('SAPI.SPVoice')
tts4file.Rate = -2
stream = win32com.client.Dispatch('SAPI.SpFileStream')
SSFM_CREATE_FOR_WRITE = 3

def writeSpeechToFile(textToSpeak, fileName):
	stream.Open(fileName, SSFM_CREATE_FOR_WRITE)
	tts4file.AudioOutputStream = stream
	tts4file.Speak(textToSpeak, 0)
	stream.Close()

count = 0
def speakWoman(textToSay):
	global count
	count += 1
	fileName = 'deleteMe' + str(count) + '.wav'
	writeSpeechToFile(textToSay, fileName)
	yield None
	woman.addAction(vizact.speak(fileName, scale=.005))
	
import viztask
def onSpeakButton():
	viztask.schedule( speakWoman(textBox.get()) )

vizact.onbuttonup(speakButton, onSpeakButton)

# Dont work first time cuz Vizard still has lock on files
def cleanup():
	import os
	files = os.listdir(os.getcwd())
	for file in files:
		if file.startswith('deleteMe'):
			try:
				os.remove(file)
			except:
				print 'Run script again without speaking to delete wav files'

vizact.onexit(cleanup)
Be sure to delete the .wav files this script leaves behind when done.

This Python Speech API wrapper code helped me figure this out.
http://archives.seul.org/pygame/user.../msg00038.html
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vizard and Augmented Reality realvision Vizard 4 04-04-2008 11:59 AM
Vizard won't run wouters Vizard 5 02-05-2008 12:12 PM
Fall 2007 release of Vizard R3 3 D Announcements 0 10-15-2007 05:50 PM
Matlab and Vizard brystewa Vizard 1 09-18-2006 04:11 PM
wxPython with Vizard farshizzo Vizard 18 09-29-2005 09:49 AM


All times are GMT -7. The time now is 01:07 AM.


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