-1

warnings.warn( Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyttsx3/init.py", line 20, in init eng = _activeEngines[driverName] File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/weakref.py", line 134, in getitem o = self.datakey KeyError: 'sapi5' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/adityagupta/Desktop/Project/assistant.py", line 10, in engine = pyttsx3.init('sapi5') File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyttsx3/init.py", line 22, in init eng = Engine(driverName, debug) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyttsx3/engine.py", line 30, in init self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyttsx3/driver.py", line 50, in init self._module = importlib.import_module(name) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 855, in exec_module File "", line 228, in _call_with_frames_removed File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyttsx3/drivers/sapi5.py", line 1, in import comtypes.client # Importing comtypes.client will make the gen subpackage ModuleNotFoundError: No module named 'comtypes'

listener = sr.Recognizer()
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)

1 Answers1

0

You can't use the sapi5 engine on macOS (which you're evidently using based on the paths in your traceback), since it's Windows only.

Based on the documentation you can just elide the sapi5 parameter to use a platform default, so:

engine = pyttsx3.init()
AKX
  • 152,115
  • 15
  • 115
  • 172