I am using Visual Studio 2017 and creating a Python application. I am getting a "member not found" error with pyttsx3 in python. The method gets called successfully the first few times, then the error gets called, and I am unable to call the method further. Can anyone please help?
I have tried updating the pyttsx3 module in both the Python 3.6 (64-bit) and Python 3.7 (32-bit) environments.
I have also tried the answer in the question at "win32com module not found". I am still getting the error
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"))
The expected result is that it should speak the output text. However, I get the following error:
I get the following error:
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
During handling of the above exception, another exception occurred:
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)
I fixed the error. It was because I was calling speechEngine = pyttsx3.init()
and speechEngine.setProperty('rate', 150)
over and over again in the method (as I had a while loop calling this method). I moved them to outside and it worked. Currently not seeing the error after any amount of time. Will see how it goes.....