1

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)  
JoeG
  • 7,191
  • 10
  • 60
  • 105
IllyShaieb
  • 111
  • 2
  • 8
  • Consider formatting your exceptions (I know it is a pain!) the same way you did your code. It will make your question more readable and thus more likely to get an answer. – JoeG Jan 24 '19 at 14:43
  • I am new to Python and exceptions. Would you be able to guide me in the right direction as to good formatting? Thanks – IllyShaieb Jan 24 '19 at 14:58
  • I think your Python formatting was fine. It was the exceptions themselves that were hard to read. I did the first one for you as an example – JoeG Jan 25 '19 at 13:08
  • I have done it, thank you for your help. Is that any better? – IllyShaieb Jan 25 '19 at 18:45
  • Try to run this code without the try/except, that could help making the exception clearer – olinox14 Jan 25 '19 at 18:51
  • 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. I moved this to outside and it worked. Currently not seeing the error after any amount of time. Will see how it goes........... – IllyShaieb Jan 25 '19 at 19:24
  • You should post that as an answer (as it is :) and not as a comment. Then you can accept it - though I think you have to wait a day.... – JoeG Jan 28 '19 at 19:46

1 Answers1

0

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.....

IllyShaieb
  • 111
  • 2
  • 8