Microsoft Sapi.SpVoice
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
stackless python 2.7.9 32bit
pywin32 220 32bit
sample code
import win32com from time import strftime tts = win32com.client.Dispatch("Sapi.SpVoice") tts.Voice = tts.GetVoices('Name=Microsoft Anna')[0] tts.AudioOutput = tts.GetAudioOutputs()[0] tts.Rate = 3 tts.Volume = 100 tts.Speak('<context ID = "date_mdy">%s</context>' % strftime("%m/%d/%Y"))
I get this traceback if it either sets the AudioOutput or the Voice.
pywin32 219 works fine
tts.Voice = tts.GetVoices('Name=Microsoft Anna')[0] File "win32com\client\dynamic.pyc", line 565, in __setattr__ com_error: (-2147352573, 'Member not found.', None, None)
I do have a workaround for setting the voice and it has to be added to the text to be spoken.
which would look like this
'<voice required="name=Microsoft Anna"><context ID = "date_mdy">%s</context></voice>' % strftime("%m/%d/%Y")
but I have not found a way around setting the audio device in this same manner,
there is a correction to the sample code. it is supposed to be import win32com.client
but I have found where the error is
win32com/client/dynamic
function _GetDescInvokeType
it reads
def _GetDescInvokeType(entry, invoke_type):
# determine the wFlags argument passed as input to IDispatch::Invoke
if not entry or not entry.desc:
return invoke_type
varkind = entry.desc[4] # from VARDESC struct returned by ITypeComp::Bind
if varkind == pythoncom.VAR_DISPATCH and invoke_type == pythoncom.INVOKE_PROPERTYGET:
return pythoncom.INVOKE_FUNC | invoke_type # DISPATCH_METHOD & DISPATCH_PROPERTYGET can be combined in IDispatch::Invoke
else:
return invoke_type
but i believe it needs to read
def _GetDescInvokeType(entry, invoke_type):
# determine the wFlags argument passed as input to IDispatch::Invoke
if not entry or not entry.desc:
return invoke_type
varkind = entry.desc[4] # from VARDESC struct returned by ITypeComp::Bind
if varkind == pythoncom.VAR_DISPATCH and invoke_type == pythoncom.INVOKE_PROPERTYGET:
return pythoncom.INVOKE_FUNC | invoke_type # DISPATCH_METHOD & DISPATCH_PROPERTYGET can be combined in IDispatch::Invoke
else:
return varkind
This does fix my issue, but I am not sure if it would cause any others. but this is sort of how the return was done in 219
I also get the error "Member not found", which only occurs with 220 and 221, 219 works fine. Our COM object is 32 bit, and I tried it with the following:
The python code uses win32com.client.Dispatch, and the error occurs on the last line, tl.Config = cn :
cr = win32com.client.Dispatch("Creator")
cn = cr.CreateConfig("config")
tl = cr.CreateTool("myTool")
tl.Config = cn
The traceback is from pywin32 221 with 32 bit Python 3.5.0:
Traceback (most recent call last):
File "example.py", line 65, in <module>
tl.Config = cn
File "C:\Python350x32\lib\site-packages\win32com\client\dynamic.py", line 565,
in setattr
self.oleobj.Invoke(entry.dispid, 0, invoke_type, 0, value)
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
Last edit: Nicole Swindell 2017-11-28