我在 python 中收到 pyttsx3 的 "member not found" 错误

I am getting a "member not found" error with pyttsx3 in python

我正在使用 Visual Studio 2017 并创建一个 Python 应用程序。我在 python 中收到 pyttsx3 的 "member not found" 错误。该方法前几次调用成功,然后调用错误,我无法进一步调用该方法。有人可以帮忙吗?

我已经尝试在 Python 3.6(64 位)和 Python 3.7(32 位)环境中更新 pyttsx3 模块。

我也试过“”问题中的答案。我仍然收到错误

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)  

我修正了错误。这是因为我在方法中一遍又一遍地调用 speechEngine = pyttsx3.init()speechEngine.setProperty('rate', 150)(因为我有一个 while 循环调用此方法)。我把它们移到外面,效果很好。目前在任何时间后都看不到错误。看看会怎样.....