4

I was having some problems when using the .getproperty('voices') attribute in pyttsx3. So I decided to uninstall it and then re-install it using PIP to see if that may fix the problem.

Previous link to when I had the .getproperty('voices') error: Why do I get an error with pyttsx3 when I try to access the properties of the voice?

Now, when I installed it again using PIP, I can't even initialize it

import pyttsx3
engine = pyttsx3.init()

It gives this error:

Traceback (most recent call last):
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\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 "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
    from comtypes.gen import SpeechLib  # comtypes
ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\gen\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE
    return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'comtypes.automation.tagVARIANT'>, <class 'comtypes.LP_POINTER(ISpeechRecoGrammar)'>), 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    engine = pyttsx3.init()
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in <module>
    engine = comtypes.client.CreateObject("SAPI.SpVoice")
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
    return _manage(obj, clsid, interface=interface)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
    obj = GetBestInterface(obj)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 110, in GetBestInterface
    mod = GetModule(tlib)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 110, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 184, in _CreateWrapper
    mod = _my_import(fullname)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 24, in _my_import
    return __import__(fullname, globals(), locals(), ['DUMMY'])
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\gen\_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 455, in <module>
    ISpeechRecoContext._methods_ = [
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 329, in __setattr__
    self._make_methods(value)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 698, in _make_methods
    prototype = WINFUNCTYPE(restype, *argtypes)
  File "C:\Users\saife\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 125, in WINFUNCTYPE
    class WinFunctionType(_CFuncPtr):
TypeError: item 1 in _argtypes_ passes a union by value, which is unsupported.
saiffarid
  • 43
  • 1
  • 2
  • 9

7 Answers7

9

Open command prompt Write:

pip uninstall pyttsx3

Then:

pip install pyttsx3==2.71

And your problem will solve.

Peyman Majidi
  • 1,777
  • 2
  • 18
  • 31
7

If you are using Linux install libespeak1 using sudo apt install libespeak1 if using debian based distros.

Sairaj K
  • 138
  • 1
  • 10
5

Try instead this:

engine= pyttsx3.init('dummy')
Unheilig
  • 16,196
  • 193
  • 68
  • 98
2

I hope you are trying to install pyttsx3 from https://pypi.org/project/pyttsx3/.

were you able to execute pip install pyttsx3 with out any issues? Are you trying to run the above code from jupyter? if yes then, please don't run the complete code at a time i.e the below code

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()

first run import pyttsx3 alone and thern try to put up your code one by one. I have faced similar issue earlier many times while running it on diferent systems. I don't know why this issue shows up but the above steps will surely do resolve the issue.

Jai
  • 819
  • 7
  • 17
  • I already have it installed. I am running the code on the Python 3.8.1 Shell. – saiffarid Feb 20 '20 at 10:28
  • pyttsx3 is supported from python 3.0 to 3.7, I recommend you to downgrade your python version to 3.7. You can find the support details on pypi.org for your confirmation. Thanks – Jai Feb 20 '20 at 10:36
  • I didn’t always have that error. When I had the getproperies(“voices”) error as described in the question. I decided to uninstall pyttsx3 and reinstall it again. Now, I am getting this initialization error – saiffarid Feb 20 '20 at 10:38
1

I don't know if you managed to work around this issue, but I had the same thing this morning and fixed it by downgrading the version of pyttsx3 from the latest to version 2.71.

There seems to be some missing commits with the latest version that haven't been resolved (if you read the thread this post is from)

Dark Hippo
  • 1,255
  • 2
  • 15
  • 35
1

You need to provide a driver key argument to init. 'dummy' or 'sapi5' would work.

engine = pyttsx3.init('dummy')

or

engine = pyttsx3.init('sapi5')
0

I was facing same problem in my project but simply changing the python version from 3.8 to 3.6 works for me.