nateshmbhat / pyttsx3

Offline Text To Speech synthesis for python
Mozilla Public License 2.0
2.15k stars 336 forks source link

pyttsx3 fails to execute when compiled #6

Closed josephalway closed 6 years ago

josephalway commented 7 years ago

Error when running Executable created with PyInstaller 3.3 on Windows 10 64-bit and Python v3.6. [pyttsx3_error.txt](https://github.com/nateshmbhat/pyttsx3/files/1455369/pyttsx3_error.txt) Example Script:

# import the speech to text module
import pyttsx3

# Initialize the Speech Engine
engine = pyttsx3.init()
# Set the words per minute rate of the Speech engine
engine.setProperty('rate', 105)
# Tell the engine what you want it to say.
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
# Tell the engine to start saying what you wanted it to and stop when it reaches the end of the queued sayings.
engine.runAndWait()
nateshmbhat commented 7 years ago

Traceback (most recent call last): File "site-packages\pyttsx3__init.py", line 44, in init File "c:\users\MyUser\appdata\local\programs\python\python36\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 "pyttsx3_example.py", line 9, in File "site-packages\pyttsx3__init.py", line 46, in init File "site-packages\pyttsx3\engine.py", line 52, in init File "site-packages\pyttsx3\driver.py", line 75, in init File "importlib\init__.py", line 126, in import_module File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 941, in _find_and_load_unlocked File "", line 219, in _call_with_frames_removed File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 953, in _find_and_load_unlocked ModuleNotFoundError: No module named 'pyttsx3.drivers' [10288] Failed to execute script pyttsx3_example

Check this #1

josephalway commented 7 years ago

I think I already tried what was suggested in that thread, but I'll give it another look.

orazdow commented 6 years ago

I'm having the same problem on windows, if anyone has found a solution please let me know

josephalway commented 6 years ago

The No module named 'pyttsx3.drivers' error seems to be an issue with PyInstaller not importing the module loaded with importlib. The old version of pyttsx has a hook file created for use with pyttsx in the Pyinstaller hooks folder. I created a copy for pyttsx3 and added pyttsx3. to drivers, drivers.sapi5, etc. That seems to load the pyttsx3.drivers module fine, but now I am running into a win32com.client error.

(This seems to fix the import error and could just be added to your .spec file for your project.) The hook I edited for PyInstaller just adds the following to whatever_my_project_is.spec file:

hiddenimports = [ 'pyttsx3.drivers', 'pyttsx3.drivers.dummy', 'pyttsx3.drivers.espeak', 'pyttsx3.drivers.nsss', 'pyttsx3.drivers.sapi5', ]

Again, I just copied the hook-pyttsx.py file in the hooks directory, made a copy named hook-pyttsx3.py in the PyInstaller folder for the hooks and added "pyttsx3." to the hidden imports.

There's also a link in the Pyinstaller hook file for work done on this same issue for the older version of pyttsx. pyinstaller and pyttsx

The New Error I am now seeing involves the use of the win32com.client package. Error when trying to run the compiled file:

Traceback (most recent call last):
  File "site-packages\pyttsx3\__init__.py", line 44, in init
  File "c:\users\MyUser\appdata\local\programs\python\python36\lib\weakref.py", line 137, in __getitem__
    o = self.data[key]()
KeyError: 'sapi5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pyttsx3_example.py", line 9, in <module>
  File "site-packages\pyttsx3\__init__.py", line 46, in init
  File "site-packages\pyttsx3\engine.py", line 52, in __init__
  File "site-packages\pyttsx3\driver.py", line 76, in __init__
  File "site-packages\pyttsx3\drivers\sapi5.py", line 22, in buildDriver
  File "site-packages\pyttsx3\drivers\sapi5.py", line 41, in __init__
  File "site-packages\pyttsx3\drivers\sapi5.py", line 83, in setProperty
  File "site-packages\win32com\client\dynamic.py", line 549, in __setattr__
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
[11956] Failed to execute script pyttsx3_example

Anyone care to take a stab at getting the win32com error fixed?

josephalway commented 6 years ago

Example of what fixes the No module named pyttsx3.drivers error:

These are the key lines: from PyInstaller.utils.hooks import collect_submodules my_hidden_imports = collect_submodules('pyttsx3') hiddenimports=my_hidden_imports,

This is a .spec file I created that collects all of the pyttsx3 submodules:

# -*- mode: python -*-
from PyInstaller.utils.hooks import collect_submodules
block_cipher = None

my_hidden_imports = collect_submodules('pyttsx3')

a = Analysis(['pyttsx3_example.py'],
             pathex=['C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\ucrt\\DLLs\\x64'],
             binaries=[],
             datas=[],
             hiddenimports=my_hidden_imports,
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='pyttsx3_example',
          debug=False,
          strip=False,
          upx=True,
          console=True )

Example hook file for pyttsx3 that avoids needing to add any of that into the spec file:

#-----------------------------------------------------------------------------
# Copyright (c) 2013-2017, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

"""
pyttsx3 imports drivers module based on specific platform.
Fount at https://github.com/nateshmbhat/pyttsx3/issues/6
"""

hiddenimports = [
    'pyttsx3.drivers',
    'pyttsx3.drivers.dummy',
    'pyttsx3.drivers.espeak',
    'pyttsx3.drivers.nsss',
    'pyttsx3.drivers.sapi5',
]
josephalway commented 6 years ago

Current Error when trying to run pyttsx3 from a Windows 10 64-bit Pyinstaller compiled executible.

Traceback (most recent call last): File "site-packages\pyttsx3__init__.py", line 44, in init File "c:\users\my_user\appdata\local\programs\python\python36\lib\weakref.py", line 137, in getitem o = self.data[key]() KeyError: 'sapi5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "pyttsx3_example.py", line 9, in engine = pyttsx3.init('sapi5') File "site-packages\pyttsx3__init.py", line 46, in init File "site-packages\pyttsx3\engine.py", line 52, in init File "site-packages\pyttsx3\driver.py", line 77, in init File "site-packages\pyttsx3\drivers\sapi5.py", line 22, in buildDriver File "site-packages\pyttsx3\drivers\sapi5.py", line 41, in init File "site-packages\pyttsx3\drivers\sapi5.py", line 83, in setProperty File "site-packages\win32com\client\dynamic.py", line 549, in setattr__ pywintypes.com_error: (-2147352573, 'Member not found.', None, None) [2244] Failed to execute script pyttsx3_example

josephalway commented 6 years ago

Success! Commenting out all of the lines in the pyinstaller hook file pyi_rth_win32comgenpy.py fixes the last issue. I'm sure there's a more elegant solution. I'll post an issue on pyinstaller and link it here.

https://github.com/pyinstaller/pyinstaller/issues/3268

suzondas commented 5 years ago

try python -m PyInstaller --hidden-import=pyttsx3.drivers --hidden-import=pyttsx3.drivers.dummy --hidden-import=pyttsx3.drivers.espeak --hidden-import=pyttsx3.drivers.nsss --hidden-import=pyttsx3.drivers.sapi5 --name YourApp yourApp_Location\main.py

Gaurav7004 commented 5 years ago

what are hidden imports how to solve the "ModuleNotFoundError: No module named 'pyttsx3.drivers.' " error?

DebarunMitra commented 4 years ago

I am getting the error for below code,

`import pyttsx3

engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') print(voices) engine.setProperty('voices', voices[0].id)`

I am using python 3.8.1 in windows 8.

Error:

`Traceback (most recent call last): File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3__init__.py", line 20, in init eng = _activeEngines[driverName] File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\weakref.py", line 131, in getitem o = self.data[key]() KeyError: 'sapi5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in from comtypes.gen import SpeechLib # comtypes ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\gen__init__.py)

During handling of the above exception, another exception occurred:

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

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\Users\jonty\Documents\PlayWithPython\VoiceAssistant\assistant.py", line 3, in engine = pyttsx3.init('sapi5') File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3__init.py", line 22, in init eng = Engine(driverName, debug) File "C:\Users\jonty\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\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py", line 50, in init self._module = importlib.import_module(name) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\importlib__init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in engine = comtypes.client.CreateObject("SAPI.SpVoice") File "C:\Users\jonty\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\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client__init__.py", line 188, in _manage obj = GetBestInterface(obj) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client\init__.py", line 110, in GetBestInterface mod = GetModule(tlib) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 110, in GetModule mod = _CreateWrapper(tlib, pathname) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 184, in _CreateWrapper mod = _my_import(fullname) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 24, in _my_import return import(fullname, globals(), locals(), ['DUMMY']) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\gen_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 63, in ISpeechBaseStream.methods = [ File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\init.py", line 329, in setattr self._make_methods(value) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\init.py", line 698, in _make_methods prototype = WINFUNCTYPE(restype, *argtypes) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\ctypes\init__.py", line 125, in WINFUNCTYPE class WinFunctionType(_CFuncPtr): TypeError: item 1 in argtypes passes a union by value, which is unsupported.`

i-am-hear commented 4 years ago

I am using python 3.8

`import pyttsx3

engian = pyttsx3.init() engian.say("hi") engian.runAndWait()`

I am getting error like this

`Traceback (most recent call last): File "C:\python3.8\lib\site-packages\pyttsx3__init__.py", line 20, in init
eng = _activeEngines[driverName] File "C:\python3.8\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/pande/Desktop/New folder/jarvis.py", line 4, in engian = pyttsx3.init() File "C:\python3.8\lib\site-packages\pyttsx3__init.py", line 22, in init eng = Engine(driverName, debug) File "C:\python3.8\lib\site-packages\pyttsx3\engine.py", line 30, in init self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "C:\python3.8\lib\site-packages\pyttsx3\driver.py", line 50, in init self._module = importlib.import_module(name) File "C:\python3.8\lib\importlib\init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "C:\python3.8\lib\site-packages\pyttsx3\drivers\sapi5.py", line 10, in import pythoncom ModuleNotFoundError: No module named 'pythoncom'` I am in win 10

lovleshsingh commented 4 years ago

I am getting the error for below code,

`import pyttsx3

engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') print(voices) engine.setProperty('voices', voices[0].id)`

I am using python 3.8.1 in windows 8.

Error:

`Traceback (most recent call last): File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3init.py", line 20, in init eng = _activeEngines[driverName] File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\weakref.py", line 131, in getitem o = self.datakey KeyError: 'sapi5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in from comtypes.gen import SpeechLib # comtypes ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\geninit.py)

During handling of the above exception, another exception occurred:

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

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\Users\jonty\Documents\PlayWithPython\VoiceAssistant\assistant.py", line 3, in engine = pyttsx3.init('sapi5') File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3init.py", line 22, in init eng = Engine(driverName, debug) File "C:\Users\jonty\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\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py", line 50, in init self._module = importlib.import_module(name) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\importlibinit.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in engine = comtypes.client.CreateObject("SAPI.SpVoice") File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\clientinit.py", line 250, in CreateObject return _manage(obj, clsid, interface=interface) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\clientinit.py", line 188, in _manage obj = GetBestInterface(obj) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\clientinit.py", line 110, in GetBestInterface mod = GetModule(tlib) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 110, in GetModule mod = _CreateWrapper(tlib, pathname) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 184, in _CreateWrapper mod = _my_import(fullname) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 24, in _my_import return import(fullname, globals(), locals(), ['DUMMY']) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\gen_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 63, in ISpeechBaseStream.methods = [ File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypesinit.py", line 329, in setattr self._make_methods(value) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypesinit.py", line 698, in _make_methods prototype = WINFUNCTYPE(restype, *argtypes) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\ctypesinit.py", line 125, in WINFUNCTYPE class WinFunctionType(_CFuncPtr): TypeError: item 1 in argtypes passes a union by value, which is unsupported.`

try installing "pip install pyttsx3==2.71" this will solve your problem

lovleshsingh commented 4 years ago

I am using python 3.8

`import pyttsx3

engian = pyttsx3.init() engian.say("hi") engian.runAndWait()`

I am getting error like this

`Traceback (most recent call last): File "C:\python3.8\lib\site-packages\pyttsx3init.py", line 20, in init eng = _activeEngines[driverName] File "C:\python3.8\lib\weakref.py", line 131, in getitem o = self.datakey KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:/Users/pande/Desktop/New folder/jarvis.py", line 4, in engian = pyttsx3.init() File "C:\python3.8\lib\site-packages\pyttsx3init.py", line 22, in init eng = Engine(driverName, debug) File "C:\python3.8\lib\site-packages\pyttsx3\engine.py", line 30, in init self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "C:\python3.8\lib\site-packages\pyttsx3\driver.py", line 50, in init self._module = importlib.import_module(name) File "C:\python3.8\lib\importlibinit.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "C:\python3.8\lib\site-packages\pyttsx3\drivers\sapi5.py", line 10, in import pythoncom ModuleNotFoundError: No module named 'pythoncom'` I am in win 10

try installing "pip install pyttsx3==2.71"

ItsNilDev commented 4 years ago

Thanks! It worked for me

SwayamTakkamore commented 4 years ago

I am using Python 3.8.2

import pyttsx3

engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') print(voices)

def speak(audio): pass

I am being got an error.

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

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\Users\admin\Desktop\Python\Jarvis with python_CodeWithHarry\jarvis.py", line 3, in engine = pyttsx3.init('sapi5') File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3__init.py", line 22, in init eng = Engine(driverName, debug) File "C:\Users\admin\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\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py", line 50, in init self._module = importlib.import_module(name) File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\importlib\init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in import win32com.client ModuleNotFoundError: No module named 'win32com'

Please solve it

nik3100 commented 3 years ago

I am getting the error for below code,

import pyttsx3 engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') print(voices) engine.setProperty('voices', voices[0].id)

I am using python 3.8.1 in windows 8.

Error:

Traceback (most recent call last): File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3__init__.py", line 20, in init eng = _activeEngines[driverName] File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\weakref.py", line 131, in **getitem** o = self.datakey KeyError: 'sapi5' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in from comtypes.gen import SpeechLib # comtypes ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\gen__init__.py) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\ctypes__init__.py", line 123, in WINFUNCTYPE return _win_functype_cache[(restype, argtypes, flags)] KeyError: (<class 'ctypes.HRESULT'>, (<class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.wintypes.LP_c_long'>), 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\Users\jonty\Documents\PlayWithPython\VoiceAssistant\assistant.py", line 3, in engine = pyttsx3.init('sapi5') File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3__init__.py", line 22, in init eng = Engine(driverName, debug) File "C:\Users\jonty\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\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\driver.py", line 50, in **init** self._module = importlib.import_module(name) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\importlib__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File "", line 991, in _find_and_load File "", line 975, in _find_and_load_unlocked File "", line 671, in _load_unlocked File "", line 783, in exec_module File "", line 219, in _call_with_frames_removed File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in engine = comtypes.client.CreateObject("SAPI.SpVoice") File "C:\Users\jonty\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\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client__init__.py", line 188, in _manage obj = GetBestInterface(obj) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client__init__.py", line 110, in GetBestInterface mod = GetModule(tlib) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 110, in GetModule mod = _CreateWrapper(tlib, pathname) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 184, in _CreateWrapper mod = _my_import(fullname) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\client_generate.py", line 24, in _my_import return **import**(fullname, globals(), locals(), ['DUMMY']) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes\gen_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 63, in ISpeechBaseStream._methods_ = [ File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes__init__.py", line 329, in **setattr** self._make_methods(value) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\site-packages\comtypes__init__.py", line 698, in _make_methods prototype = WINFUNCTYPE(restype, *argtypes) File "C:\Users\jonty\AppData\Local\Programs\Python\Python38\lib\ctypes__init__.py", line 125, in WINFUNCTYPE class WinFunctionType(_CFuncPtr): TypeError: item 1 in _argtypes_ passes a union by value, which is unsupported.

try installing "pip install pyttsx3==2.71" this will solve your problem

you are right , i have installed 2.71 and problem is solved , i have tried many times with diff solutions but not work and thats work . so insatll 2.71 v of pyttsx3