从 com 类型传入此 CreateObject 时出错?

问题描述

这是我的简单代码

from comtypes.client import CreateObject
engine = CreateObject("SAPI.SpVoice")
#stream = CreateObject("SAPI.SpFileStream")

出现了这么多错误

回溯(最近一次调用最后一次): 文件“E:\Python\lib\ctypes_init_.py”,第 123 行,在 WINFUNCTYPE 中 return win_functype_cache[(restype,argtypes,flags)] KeyError: (,(,),0) 在处理上述异常的过程中,又发生了一个异常: 回溯(最近一次调用最后一次): 文件“E:\Python\cv2_tutorials\Text to Speech\text2speech.py​​”,第 2 行,在 engine = CreateObject("SAPI.SpVoice") 文件“E:\Python\lib\site-packages\comtypes\client_init.py”,第 250 行,在 CreateObject 中 return manage(obj,clsid,interface=interface) 文件“E:\Python\lib\site-packages\comtypes\client_init.py”,第 188 行,manage obj = GetBestInterface(obj) 文件“E:\Python\lib\site-packages\comtypes\client_init.py”,第 110 行,在 GetBestInterface mod = GetModule(tlib) GetModule 中的文件“E:\Python\lib\site-packages\comtypes\client_generate.py”,第 118 行 mod = _CreateWrapper(tlib,路径名) 文件“E:\Python\lib\site-packages\comtypes\client_generate.py”,第 198 行,在 _CreateWrapper mod = my_import(fullname) my_import 中的文件“E:\Python\lib\site-packages\comtypes\client_generate.py”,第 19 行 return import(fullname,globals(),locals(),['DUMMY']) 文件“E:\Python\lib\site-packages\comtypes\gen_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py”,第 438 行,在 ISpeechBaseStream.方法 = [ 文件“E:\Python\lib\site-packages\comtypes_init.py”,第 323 行,setattr self.make_methods(value) 文件“E:\Python\lib\site-packages\comtypes_init.py”,第 692 行,make_methods 原型 = WINFUNCTYPE(restype,*argtypes) 文件“E:\Python\lib\ctypes_init.py”,第 125 行,在 WINFUNCTYPE 中 类 WinFunctionType(_CFuncPtr): 类型错误argtypes 中的第 1 项按值传递联合,这是不受支持的。

我知道一件事,这是一个非常简单的错误,但我找不到。

解决方法

好吧,我得到了自己问题的答案 答案很简单:- **只需卸载 pyttsx3 和 comtypes :**

pip uninstall pyttsx3
pip uninstall comtypes

**然后输入以下内容重新安装它们:**

pip install comtypes
pip install -Iv pyttsx3==2.6 -U

它会解决问题,稍后谢谢