NameError: name 'objc' is not defined
Ziaeemehr opened this issue · 6 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
"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.
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()
Had to remove attr['VoiceAge']
as well from NSSS.py
in order to get it to work. Apparently this ruins audio further.
Maybe downgrade pyobjc to 9.0.1 can help you.
Same issue with macOS 14.3.1 and Python 3.10
updated readme with :
For Mac, If you face error related to "objc" when running the
init()
method :
Install 9.0.1 version of pyobjc : "pip install pyobjc==9.0.1"