![]() |
|
#2
|
|||
|
|||
|
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)
This Python Speech API wrapper code helped me figure this out. http://archives.seul.org/pygame/user.../msg00038.html
__________________
Paul Elliott WorldViz LLC |
|
|
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 |