pyttsx3: apple pyttsx3.init() not working

I have a new apple mac book pro os version 10.12.5. I tried following the instruction. Pip3 install seemed to work. Import ran no errors. The next command pyttsx3.init() resulted in

>>> engine = pyttsx3.init()
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/__init__.py", line 44, in init
    eng = _activeEngines[driverName]
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/weakref.py", line 137, in __getitem__
    o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/__init__.py", line 46, in init
    eng = Engine(driverName, debug)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/engine.py", line 52, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/driver.py", line 75, in __init__
    self._module = importlib.import_module(name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/drivers/nsss.py", line 10, in <module>
    class NSSpeechDriver(NSObject):
objc.BadPrototypeError: Objective-C expects 1 arguments, Python argument has 2 arguments for <unbound selector initWithProxy of NSSpeechDriver at 0x109202238>

Any help or advice would be most useful. Thanks for this project.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 23 (8 by maintainers)

Most upvoted comments

I found a solution: Because of changes in PyObjC (v3.1 up?!) you have to add

@objc.python_method

as an decorator before some of the methods of class NSSpeechDriver in the file pyttsx3/drivers/nsss.py as noted here:

@objc.python_method def initWithProxy(self, proxy):

@objc.python_method def say(self, text):

@objc.python_method def _toVoice(self, attr):

@objc.python_method def getProperty(self, name):

@objc.python_method def setProperty(self, name, value):

I used “trial and error” to find the methods I had to decorate. Also I had to remove the conversion to unicode in the “say” method, from self.tts.startSpeakingString(unicode(text))

to

self.tts.startSpeakingString(text)

(on Python 3). Before I removed the conversion to unicode the execution stopped at this line without an error.

Hi,

I have a MacBook Pro with Chip M2 and Someone 14.0 and I had the same problem.

I’ve solved it installing the version 9.0.1 of pyobjc: pip install pyobjc==9.0.1

Then, this code finally works and sounds:

`def speak(message):

# turn on pyttsx3
engine = pyttsx3.init()

# say message with voice
engine.say(message)
engine.runAndWait()

speak(“Hi world”)`

OK! I solve the issue by using ‘pip install pyobjc’. I think this problem is related to the new MacOS Sierra 10.13.1

Hi,

I have a MacBook Pro with Chip M2 and Someone 14.0 and I had the same problem.

I’ve solved it installing the version 9.0.1 of pyobjc: pip install pyobjc==9.0.1

Then, this code finally works and sounds:

`def speak(message):

# turn on pyttsx3
engine = pyttsx3.init()

# say message with voice
engine.say(message)
engine.runAndWait()

speak(“Hi world”)`

installing version of pyobjc==9.0.1 worked for me

i am on M1 mac 2020, i also got this to work doing the following

pip3 install pyobjc==9.0.1
pip3 install pyttsx3

then i created speak.py
import pyttsx3
engine = pyttsx3.init()
engine.say("Someone get these not so friendly snakes off my plane!")
engine.runAndWait()

> python3 speak.py

I solve the issue by using ‘pip install pyobjc’ too, python3 MACOS 10.14