Visual studio code Python键错误';sapi5';,我不能理解错误

Visual studio code Python键错误';sapi5';,我不能理解错误,visual-studio-code,python-3.8,Visual Studio Code,Python 3.8,以前曾提出过一个此类问题,但没有太大帮助。我正在Windows 10操作系统中使用Python3.8版。我得到了一个错误,KeyError:'sapi5'。不知道为什么会发生此错误。请看下面给出的代码。我的代码是- import pyttsx3 engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') engine.setProperty('voices', voices[0].id) 误差相当大。有人能帮我吗

以前曾提出过一个此类问题,但没有太大帮助。我正在Windows 10操作系统中使用Python3.8版。我得到了一个错误,KeyError:'sapi5'。不知道为什么会发生此错误。请看下面给出的代码。我的代码是-

import pyttsx3

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voices', voices[0].id)
误差相当大。有人能帮我吗

Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\weakref.py", line 131, in __getitem__
    o = self.data[key]()
KeyError: 'sapi5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
    from comtypes.gen import SpeechLib  # comtypes
ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\gen\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE
    return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'ctypes.c_long'>, <class 'comtypes.automation.tagVARIANT'>, <class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.c_long'>, <class 'ctypes.c_long'>), 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "g:/saurav/Assistant/VA/MyAssistant.py", line 9, in <module>
    engine = pyttsx3.init('sapi5')
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in <module>
    engine = comtypes.client.CreateObject("SAPI.SpVoice")
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
    return _manage(obj, clsid, interface=interface)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
    obj = GetBestInterface(obj)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 110, in GetBestInterface
    mod = GetModule(tlib)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 110, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 184, in _CreateWrapper
    mod = _my_import(fullname)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 24, in _my_import
    return __import__(fullname, globals(), locals(), ['DUMMY'])
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\gen\_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 140, in <module>   
    ISpeechRecoGrammar._methods_ = [
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 329, in __setattr__
    self._make_methods(value)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 698, in _make_methods
    prototype = WINFUNCTYPE(restype, *argtypes)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 125, in WINFUNCTYPE
    class WinFunctionType(_CFuncPtr):
TypeError: item 2 in _argtypes_ passes a union by value, which is unsupported.
回溯(最近一次呼叫最后一次):
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\pyttsx3\\uuuu init\uuuu.py”,第20行,在init中
eng=\u活动引擎[driverName]
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\weakref.py”,第131行,在u\getitem中__
o=自身数据[键]()
KeyError:“sapi5”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\hp\AppData\Local\Programs\Python38-32\lib\site packages\pyttsx3\drivers\sapi5.py”,第3行,在
从comtypes.gen导入SpeechLib#comtypes
ImportError:无法从“comtypes.gen”(C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\gen\\uuuu init\uuuu.py)导入名称“SpeechLib”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
WINFUNCTYPE中的文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\ctypes\\uuuuuu init\uuuuuu.py”,第123行
return\u win\u functype\u cache[(restype,argtypes,flags)]
KeyError:(,(,,),0)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“g:/saurav/Assistant/VA/MyAssistant.py”,第9行,在
engine=pyttsx3.init('sapi5')
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\pyttsx3\\uuuu init\uuu.py”,第22行,在init中
eng=引擎(驱动器名称,调试)
文件“C:\Users\hp\AppData\Local\Programs\Python38-32\lib\site packages\pyttsx3\engine.py”,第30行,在\uuu init中__
self.proxy=driver.DriverProxy(weakref.proxy(self)、driverName、debug)
文件“C:\Users\hp\AppData\Local\Programs\Python38-32\lib\site packages\pyttsx3\driver.py”,第50行,在\uuu init中__
self.\u模块=导入lib.import\u模块(名称)
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\importlib\\uuuuuu init\uuuuuu.py”,第127行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
文件“”,第1014行,在\u gcd\u导入中
文件“”,第991行,在“查找”和“加载”中
文件“”,第975行,在“查找”和“加载”中解锁
文件“”,第671行,在\u加载\u解锁
exec_模块中第783行的文件“”
文件“”,第219行,在“调用”中,删除了“帧”
文件“C:\Users\hp\AppData\Local\Programs\Python38-32\lib\site packages\pyttsx3\drivers\sapi5.py”,第6行,在
engine=comtypes.client.CreateObject(“SAPI.SpVoice”)
CreateObject中的文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\client\ \uuuuuu init\uuuuuu.py”,第250行
返回管理(obj,clsid,接口=接口)
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\client\\uuuu init\uuuu.py”,第188行,在\u manage中
obj=GetBestInterface(obj)
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\client\ \uuuu init\uuuu.py”,第110行,在GetBestInterface中
mod=GetModule(tlib)
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\client\\u generate.py”,第110行,在GetModule中
mod=\u CreateWrapper(tlib,路径名)
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\client\\ u generate.py”,第184行,位于\u CreateWrapper中
mod=\u我的\u导入(全名)
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\client\\u generate.py”,第24行,在“我的导入”中
return uuu import uuuuu(全名,globals(),locals(),['DUMMY']))
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\gen\\ C866CA3A\U 32F7\U 11D2\U 9602\U 00C04F8EE628\U 0\U 5\U 4.py”,第140行,in
ISPeechRecogram.\u方法\uu=[
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\\uuuuuu init\uuuuuu.py”,第329行,位于__
自我制作方法(值)
文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\site packages\comtypes\\uuuuuuuuu init\uuuuuuuuu.py”,第698行,在\u make\u方法中
prototype=WINFUNCTYPE(重新类型,*argtypes)
WINFUNCTYPE中的文件“C:\Users\hp\AppData\Local\Programs\Python\Python38-32\lib\ctypes\ \uuuuuu init\uuuuuuu.py”,第125行
类WinFunctionType(\u CFuncPtr):
TypeError:_argtypes_中的项2通过值传递union,这是不受支持的。
  • 首先使用以下命令卸载pyttsx3

    pip卸载pyttsx3

  • 然后使用以下命令安装pyttsx3 2.6版

    pip安装pyttsx3==2.6