pyttsx3在新安装的Windows 10上不起作用

时间:2018-08-12 14:32:01

标签: python windows-10 text-to-speech pyttsx

我已经全新安装了Windows 10,并且正在尝试运行以下代码。

import pyttsx3;
engine = pyttsx3.init();
engine.say("I will speak this text");
engine.runAndWait() ;

此功能可用于我以前的Windows 10安装,但现在却出现以下错误

Traceback (most recent call last):
  File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\__init__.py", line 44, in init
    eng = _activeEngines[driverName]
  File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\weakref.py", line 137, 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/ayush/Desktop/sample.py", line 2, in <module>
    engine = pyttsx3.init();
  File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\__init__.py", line 46, in init
    eng = Engine(driverName, debug)
  File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\engine.py", line 52, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\driver.py", line 75, in __init__
    self._module = importlib.import_module(name)
  File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
    import win32com.client
  File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\win32com\__init__.py", line 5, in <module>
    import win32api, sys, os
ImportError: DLL load failed: %1 is not a valid Win32 application.

我在Windows 10上使用python 3.6.6 64位。

我花了很多时间尝试不同的解决方案,例如重新安装python,尝试python 3.5和3.7版本,重新安装pyttsx3,还尝试了一些相关问题中给出的解决方案,但是没有任何效果。

预先感谢

2 个答案:

答案 0 :(得分:1)

看起来像win32api.pyd(实际上是DLL)不是Win32应用程序。因此,我认为它正在将64位驱动程序加载到32位运行时。

在这种情况下,我将尝试卸载64位python,删除其文件夹并安装32位版本。我相信这会解决您的问题,因为您实际上不需要64位python。


现在问题出在win32*.pyd s中,因此您的 pyttsx3似乎是32位

  

根据pypi.org ,您可以尝试pip install pypiwin32修复 win32 win32api 错误。

答案 1 :(得分:-1)

我尝试安装Python 32位,但是使用所有可用选项(例如完整的库)进行了自定义,这样做可以打破错误!只需重新启动.exe启动器,点击“修改”,然后安装每个选项即可!