问题描述
我正在尝试在我的计算机上启动并运行 pyttsx3.我做了 pip install pyttsx3 和 pip install pypiwin32 我可以在我的 python 目录中看到它们.
I am trying to get pyttsx3 up and running on my computer. I did pip install pyttsx3 and pip install pypiwin32 I can see both of them in my python directory.
我输入此代码进行测试:
I type this code in to test it:
import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
结果是这样的:
回溯(最近一次调用最后一次):文件C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3__init__.py",第 44 行,在 init 中eng = _activeEngines[driverName]getitem 中的文件C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\weakref.py",第 131 行o = self.datakey密钥错误:无
Traceback (most recent call last): File "C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3__init__.py", line 44, in init eng = _activeEngines[driverName] File "C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\weakref.py", line 131, in getitem o = self.datakeyKeyError: None
在处理上述异常的过程中,又发生了一个异常:
During handling of the above exception, another exception occurred:
回溯(最近一次调用最后一次):文件C:\Users\Danny\Desktop\python text to speech.py",第 9 行,在引擎 = pyttsx3.init()文件C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3__init__.py",第 46 行,在 init 中eng = 引擎(驱动程序名称,调试)文件C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\engine.py",第 52 行,initself.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)文件C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\driver.py",第 77 行,initself._driver = self._module.buildDriver(weakref.proxy(self))文件C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py",第 22 行,在 buildDriver返回 SAPI5Driver(代理)文件C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py",第 41 行,initself.setProperty('声音', self.getProperty('声音'))文件C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py",第 83 行,在 setPropertyself._tts.Voice = 令牌文件C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\win32com\client\dynamic.py",第 549 行,setattrself.oleobj.Invoke(entry.dispid, 0, invoke_type, 0, value)pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
Traceback (most recent call last): File "C:\Users\Danny\Desktop\python text to speech.py", line 9, in engine = pyttsx3.init() File "C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3__init__.py", line 46, in init eng = Engine(driverName, debug) File "C:\Users\Danny\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\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\driver.py", line 77, in init self._driver = self._module.buildDriver(weakref.proxy(self)) File "C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py", line 22, in buildDriver return SAPI5Driver(proxy) File "C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py", line 41, in init self.setProperty('voice', self.getProperty('voice')) File "C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py", line 83, in setProperty self._tts.Voice = token File "C:\Users\Danny\AppData\Local\Programs\Python\Python36\lib\site-packages\win32com\client\dynamic.py", line 549, in setattr self.oleobj.Invoke(entry.dispid, 0, invoke_type, 0, value)pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
我在另一台已经安装了两者的计算机上尝试了同样的事情,并得到了相同的输出.知道 win32com 发生了什么吗?我没有这方面的经验,而且很迷茫.谢谢.
I tried the same thing on another computer that already had both installed, and got the same output. Any idea what is going on with the win32com? I have no experience with it and am pretty lost. Thanks.
推荐答案
好的,所以我在与 win32com 模块相关的其他问题中找到了答案.基本上你需要做的是导航到你的 python 脚本文件夹(在我的例子中:C:\Users\Danny\AppData\Local\Programs\Python\Python36\Scripts)并运行 pywin32_postinstall.运行该脚本后,它完美运行!
Ok, so I found the answer looking at other problems that were related to the win32com module. Basically what you need to do is navigate to your python scripts folder (in my case: C:\Users\Danny\AppData\Local\Programs\Python\Python36\Scripts) and run pywin32_postinstall. Upon running that script, it works perfectly!
干杯!
这篇关于找不到 win32com 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!