text to speech via Python 3.x , 088

Thats right.
You have to import the module into each DAT’s name space.
Otherwise it would be a real mess of conflicting names everywhere.
The sys.path.append only needs to be done once though (and before the imports).

Not to worry though, subsequent imports are fast, as the module is already sitting in memory,
and you’re just pointing an object to that shared instance internally.

So I’m trying to make some dynamic content for my little voice box. if my executeDAT looks like this- is this ideal in terms of non-redundant importing and execution?

[code]# me is this DAT.

etc.

sys.path.append(“C:/Python33/Lib/site-packages/win32”)
sys.path.append(“C:/Python33/Lib/site-packages/win32/lib”)
sys.path.append(“C:/Python33/Lib/site-packages/Pythonwin”)

import win32com.client
speech = win32com.client.Dispatch(‘Sapi.SpVoice’)

def tableChange(dat):
speech.Speak( op(‘table1’)[0,0])
return

def rowChange(dat, rows):
return

def colChange(dat, cols):
return

def cellChange(dat, cells, prev):
return

def sizeChange(dat):
return
[/code]

I see what you mean about SAPI pausing the TD timeline. I learnt a lot on this thread/project, but I am weary of Win7’s weak TTS implementations. I think I will put it to bed/change my goals a bit. I’ll probably pick this thread up again in a yr or 2 :wink:

Here’s my work for anyone going down the same rabbit hole. Thks again for all yer help, Rob.
SuccessfulSpeaking01.39.toe (21.6 KB)

One thing with the script, you run the risk of continuously appending those paths to sys.path everytime the DAT is recompiled / edited.

You could put a check in first:

 if not 'win32com.client' in sys.modules:
     sys.path.append...
     sys.path.append...
     sys.path.append...

The import statement still needs to be executed regardless.

Also, easy to launch the .Speak in a separate thread:

 from threading import Thread
 def myfunc(speech, text):
     speech.Speak(text)

 def tableChange(dat):
     t = Thread(target=myfunc, args=(speech, op('null3')[0,0].val ))
     t.start()  
    return

Notice how I pass in op(‘null3’)[0,0].val, and not op(‘null3’)[0,0].
The former is a string, the later is a Cell object.

Passing TouchDesigner objects in separate threads is not supported, and will lead to instability.

Cheers
Rob

hey thanks, you’ve brought me back! It works as advertised. And I learned a bit of what multi-threading is in the process. Cheers. cheers. Cheers.

today it no worky on bootup:
what does this exception mean ?:

python >>> Exception in thread Thread-5: Traceback (most recent call last): File "C:\Program Files\Derivative\TouchDesigner088\bin\lib\threading.py", line 637, in _bootstrap_inner self.run() File "C:\Program Files\Derivative\TouchDesigner088\bin\lib\threading.py", line 594, in run self._target(*self._args, **self._kwargs) File "/project1/datexec1", line 23, in myfunc File "<COMObject Sapi.SpVoice>", line 3, in Speak pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147221008), None)

Hm. Whats your full script now?
Are you running 32 or 64?
Nothing changed before?

The first time I execute it doesn’t complain, but the next trigger gives that message. Looks like threads are piling up but not executing?

script:

[code]#

If rows or columns are deleted, sizeChange will be called instead of row/col/cellChange.

if not ‘win32com.client’ in sys.modules:
sys.path.append(“C:/Python33/Lib/site-packages/win32”)
sys.path.append(“C:/Python33/Lib/site-packages/win32/lib”)
sys.path.append(“C:/Python33/Lib/site-packages/Pythonwin”)

import win32com.client
speech = win32com.client.Dispatch(‘Sapi.SpVoice’)

from threading import Thread
def myfunc(speech, text):
speech.Speak(text)

def tableChange(dat):
t = Thread(target=myfunc, args=(speech, op(‘null3’)[0,0].val))
t.start()
return

def rowChange(dat, rows):
return

def colChange(dat, cols):
return

def cellChange(dat, cells, prev):
return

def sizeChange(dat):
return
[/code]

i’m running 64 bit

I thought it was possible to make your own with an API or a basic app. , but I’ve kind of put this on hold for a bit.