Tommy
Tommy

Reputation: 144

Pyttsx3 doesn't work on Python 3.11 script, Mac M1

I get a weird error when I try to execute the initialization of Pyttssx3 module (successfully installed), in a Python 3.11 script. I just executed:

import pyttsx3
engine=pyttsx3.init()

And I get, from the related nsss.py library:

class NSSpeechDriver(NSObject):
    @objc.python_method
    NameError: name 'objc' is not defined. Did you mean: 'object'?

Stacktrace:

Traceback (most recent call last):
  File ".venv/lib/python3.10/site-packages/pyttsx3/__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "~/.pyenv/versions/3.10.7/lib/python3.10/weakref.py", line 137, in __getitem__
    o = self.data[key]()
KeyError: 'nsss'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/.pyenv/versions/3.10.7/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "~/.pyenv/versions/3.10.7/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "~/dev/thea/thea/tts.py", line 13, in <module>
    main()
  File "~/dev/thea/thea/tts.py", line 7, in main
    engine = init(driverName="nsss")
  File ".venv/lib/python3.10/site-packages/pyttsx3/__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File ".venv/lib/python3.10/site-packages/pyttsx3/engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File ".venv/lib/python3.10/site-packages/pyttsx3/driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "~/.pyenv/versions/3.10.7/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File ".venv/lib/python3.10/site-packages/pyttsx3/drivers/nsss.py", line 12, in <module>
    class NSSpeechDriver(NSObject):
  File ".venv/lib/python3.10/site-packages/pyttsx3/drivers/nsss.py", line 13, in NSSpeechDriver
    @objc.python_method
NameError: name 'objc' is not defined. Did you mean: 'object'?

Upvotes: 1

Views: 2215

Answers (3)

Arav Shakya
Arav Shakya

Reputation: 9

Hey Tommy I installed pyttsx3 and got the sam obj error though I'm a bit late but I think this can help many other. so enjoy.

If you are using Virtual env the go to

lib>python>pyttsx3>nsss.py

And what we are doing is we are replacing super() with objc.super()

and I dont want you guys to be in trouble so just Remove all the code in nsss.py and paste what Im sending

Paste this in nsss.py( remove everything and paste it ):

Doc link: https://docs.google.com/document/d/1lCTSv6vCCXSLI_w55Bd43ExlLPQa8n2m5oesFFuFLQE/edit?usp=sharing

This will 100% solve all error :) Thank me later Just in case you are not using venv then find the nsss.py file in you global environment and do the same.

Upvotes: -1

MobileMateo
MobileMateo

Reputation: 459

Installing this package solved the problem for me.

pip install py3-tts

Upvotes: 2

jcemp
jcemp

Reputation: 46

installing version of pyobjc==9.0.1 worked for me

Upvotes: 1

Related Questions