Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyttsx3 fails to execute when compiled #6

Closed
josephalway opened this issue Nov 8, 2017 · 16 comments
Closed

pyttsx3 fails to execute when compiled #6

josephalway opened this issue Nov 8, 2017 · 16 comments

Comments

@josephalway
Copy link

josephalway commented Nov 8, 2017

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
Copy link
Owner

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.datakey
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
Copy link
Author

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

@orazdow
Copy link

orazdow commented Jan 2, 2018

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

@josephalway
Copy link
Author

josephalway commented Jan 24, 2018

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
Copy link
Author

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
Copy link
Author

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.datakey
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
Copy link
Author

josephalway commented Feb 2, 2018

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.

pyinstaller/pyinstaller#3268

@suzondas
Copy link

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
Copy link

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

@DebarunMitra
Copy link

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

@i-am-hear
Copy link

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.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\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
Copy link

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

@lovleshsingh
Copy link

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

try installing "pip install pyttsx3==2.71"

@ItsNilDev
Copy link

ItsNilDev commented Sep 21, 2020

Thanks! It worked for me

@SwayamTakkamore
Copy link

SwayamTakkamore commented Sep 30, 2020

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.datakey
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
Copy link

nik3100 commented Feb 10, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests