0

I want to use pyttsx3 in my code but I always have that error:

Traceback (most recent call last):
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\weakref.py", line 131, in __getitem__
    o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test3.py", line 3, in <module>
    engine = pyttsx3.init()
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py", line 52, in __init__
    self._driver = self._module.buildDriver(weakref.proxy(self))
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 30, in buildDriver
    return SAPI5Driver(proxy)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 35, in __init__
    self._tts = comtypes.client.CreateObject('SAPI.SPVoice')
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
    return _manage(obj, clsid, interface=interface)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
    obj = GetBestInterface(obj)
  File "C:\Users\Romain\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\__init__.py", line 112, in GetBestInterface
    interface = getattr(mod, itf_name)
AttributeError: module 'comtypes.gen.SpeechLib' has no attribute 'ISpeechVoice'

And my code:

import pyttsx3
engine = pyttsx3.init()
engine.say("This is a test")
engine.runAndWait()

Can you please help me ? (using Python 3.8.3 and Studio code)

RomainLB
  • 53
  • 1
  • 10
  • Does this answer your question? https://stackoverflow.com/questions/60307452/pyttsx3-initialization-error-cant-use-pyttsx3 – Ronald Jun 25 '20 at 13:26
  • I tried with `engine = pyttsx3.init('dummy')`and now it just do nothing: no error and no voice... – RomainLB Jun 25 '20 at 13:30

2 Answers2

1

I decided to reinstall pyttsx3 with another version and it worked (command:pip uninstall pyttsx3and pip install pyttsx3==2.7)

RomainLB
  • 53
  • 1
  • 10
1

The problem arises due to older version of comtypes (a default module required in pyttsx3) so no need to install older version of pyttsx3

Just type the following in cmd:

pip install --upgrade comtypes

Now you are good to go

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Adi bhai
  • 23
  • 4