pyttsx3 icon indicating copy to clipboard operation
pyttsx3 copied to clipboard

NameError: name 'objc' is not defined

Open Ziaeemehr opened this issue 4 months ago • 5 comments

I am getting the following error calling

import pyttsx3
engine = pyttsx3.init()
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyttsx3/__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/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 "tt.py", line 2, in <module>
    engine = pyttsx3.init()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyttsx3/__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/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.8/lib/python3.8/site-packages/pyttsx3/driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/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 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyttsx3/drivers/nsss.py", line 12, in <module>
    class NSSpeechDriver(NSObject):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyttsx3/drivers/nsss.py", line 13, in NSSpeechDriver
    @objc.python_method
NameError: name 'objc' is not defined

I used pip install pyttsx3 on conda env running on mac 2020, Sonma 14.3. I tried with python3.8 and 3.10. I already installed

brew install espeak
brew install ffmpeg
brew install libtool 

Ziaeemehr avatar Mar 02 '24 22:03 Ziaeemehr

"from Foundation import *" used to import "objc" in the local dictinary. However, it is not the case in the recent versions of Python/objc. It is better import objc module explicitly using "import objc" in nsss.py.

noboruatkek avatar Mar 04 '24 00:03 noboruatkek

I have gotten the same issue running pyttsx3 with Python 3.11.0 on MacOS 14.0

Solved by adding to nsss.py

import objc

and correcting line self = super(NSSpeechDriver, self).init() to

self = objc.super(NSSpeechDriver, self).init()

centineo avatar Mar 30 '24 16:03 centineo

Had to remove attr['VoiceAge'] as well from NSSS.py in order to get it to work. Apparently this ruins audio further.

StupidRepo avatar Apr 12 '24 17:04 StupidRepo

Maybe downgrade pyobjc to 9.0.1 can help you.

Abeautifulsnow avatar Apr 20 '24 02:04 Abeautifulsnow

Same issue with macOS 14.3.1 and Python 3.10

edobrynin-dodo avatar May 06 '24 17:05 edobrynin-dodo