首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:模块“comtypes.gen.SpeechLib”没有属性“ISpeechVoice”

AttributeError:模块“comtypes.gen.SpeechLib”没有属性“ISpeechVoice”
EN

Stack Overflow用户
提问于 2020-06-25 13:17:48
回答 2查看 1.6K关注 0票数 0

我想在我的代码中使用pyttsx3,但是我总是有这样的错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\weakref.py", line 131, in __getitem__
    o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test3.py", line 3, in <module>
    engine = pyttsx3.init()
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py", line 52, in __init__
    self._driver = self._module.buildDriver(weakref.proxy(self))
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 30, in buildDriver
    return SAPI5Driver(proxy)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 35, in __init__
    self._tts = comtypes.client.CreateObject('SAPI.SPVoice')
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
    return _manage(obj, clsid, interface=interface)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
    obj = GetBestInterface(obj)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\__init__.py", line 112, in GetBestInterface
    interface = getattr(mod, itf_name)
AttributeError: module 'comtypes.gen.SpeechLib' has no attribute 'ISpeechVoice'

我的密码是:

代码语言:javascript
复制
import pyttsx3
engine = pyttsx3.init()
engine.say("This is a test")
engine.runAndWait()

你能帮帮我吗?(使用Python3.8.3和Studio代码)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-06-25 13:42:01

我决定用另一个版本重新安装pyttsx3,它成功了(命令:pip uninstall pyttsx3pip install pyttsx3==2.7)

票数 1
EN

Stack Overflow用户

发布于 2021-05-24 14:41:00

这个问题是由于comtypes的旧版本(pyttsx3中所需的默认模块)而产生的,因此不需要安装旧版本的pyttsx3

只需在cmd中键入以下内容:

代码语言:javascript
复制
pip install --upgrade comtypes

现在你可以走了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62576302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档