我正在使用Visual Studio 2017并创建一个Python应用程序。我在pyttsx3中收到“找不到成员”错误。该方法在最初的几次成功调用,然后错误被调用,而我无法进一步调用该方法。谁能帮忙吗?
我曾尝试在Python 3.6(64位)和Python 3.7(32位)环境中更新pyttsx3模块。
我还尝试了问题“ win32com module not found”中的答案。我仍然遇到错误
def Say(text):
try:
speechEngine = pyttsx3.init()
speechEngine.setProperty('rate', 150)
print("{0} | Lola: {1}".format(TimeOfDay(), text))
speechEngine.say(text)
speechEngine.runAndWait()
logging.info("Spoken words ({0})".format(text))
except Exception as e:
logging.error("Exception occurred", exc_info=True)
print("{0} | Lola: {1}".format(TimeOfDay(),"I have come across an error in my code. See the log for details"))
预期结果是它应该说出输出文本。但是,出现以下错误:
我收到以下错误:
Exception occurred
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\__init__.py", line 44, in init
eng = _activeEngines[driverName]
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last):
File "C:\Users\IllyS\OneDrive\Programming\My Programs\GitHub\Lola-Mark-II\Lola\Lola.py", line 23, in Say
speechEngine = pyttsx3.init()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\__init__.py", line 46, in init
eng = Engine(driverName, debug)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\engine.py", line 52, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\driver.py", line 77, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\drivers\sapi5.py", line 22, in buildDriver
return SAPI5Driver(proxy)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\drivers\sapi5.py", line 41, in __init__
self.setProperty('voice', self.getProperty('voice'))
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\drivers\sapi5.py", line 72, in getProperty
return self._tts.Voice.Id
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\win32com\client\__init__.py", line 474, in __getattr__
return self._ApplyTypes_(*args)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\win32com\client\__init__.py", line 467, in _ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, 'Member not found.', None, 0, -2147201001), None)
答案 0 :(得分:0)
我已修复错误。这是因为我在该方法中一次又一次地调用speechEngine = pyttsx3.init()
和speechEngine.setProperty('rate', 150)
(因为我有一个 while 循环调用此方法)。我将它们移到外面,并且有效。当前在任何时间后都看不到错误。会看到进展的情况.....