簡體   English   中英

Python pyttsx3 在啟動時拋出錯誤

[英]Python pyttsx3 throws an error on startup

Python 3.6

有一段代碼:

import pyttsx3
engine = pyttsx3.init()
engine.say("Hello World!")
engine.runAndWait()

在啟動時,它會報錯:

Traceback (most recent call last):
  File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\andre\AppData\Local\Programs\Python\Python36\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 "C:/Users/andre/PycharmProjects/Ilona/main.py", line 2, in <module>
    engine = pyttsx3.init()
  File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\driver.py", line 52, in __init__
    self._driver = self._module.buildDriver(weakref.proxy(self))
  File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 30, in buildDriver
    return SAPI5Driver(proxy)
  File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 47, in __init__
    self.setProperty('voice', self.getProperty('voice'))
  File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 100, in setProperty
    token = self._tokenFromId(value)
  File "C:\Users\andre\PycharmProjects\Ilona\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 80, in _tokenFromId
    tokens = self._tts.GetVoices()
_ctypes.COMError: (-2147200967, None, (None, None, None, 0, None))

安裝了 Pywin32、pypiwin32 和 pyttsx3 模塊。

使用 PyCharm。

該怎么辦?

打開命令提示符/終端並輸入:

  1. pip uninstall pyttsx3
  2. pip install pyttsx3==2.71

如果這不起作用,請將engine=pyttsx3.init()替換為engine=pyttsx3.init('dummy')

  1. pip uninstall pyttsx3
  2. pip install -u pipenv
  3. pipenv install pyttsx3希望這有效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM