First of all, I’m using:
- Windows 10
- Python 3.6.2 (but I’ve tried with Python 3.5.4 too)
- pyttsx3 module
I’m trying to use pyttsx3 but I just can’t initialize it, with the official code examples.
My code (just like the examples from here and here):
JavaScript
x
5
1
import pyttsx3
2
engine = pyttsx3.init()
3
engine.say('Just a sample text.')
4
engine.runAndWait()
5
And the second line gives me this error:
AttributeError: module ‘pyttsx3’ has no attribute ‘init’
I installed it with PIP:
JavaScript
1
2
1
pip install pyttsx3
2
And I tried to fix it installing pypiwin32 but it still doesn’t work:
JavaScript
1
2
1
pip install pypiwin32
2
When I execute the following script:
JavaScript
1
3
1
import pyttsx3
2
print(dir(pyttsx3))
3
I get this:
JavaScript
1
2
1
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'pyttsx3']
2
There is this:
JavaScript
1
8
1
drivers (folder)
2
__pycache__ (folder)
3
driver.py
4
engine.py
5
six.py
6
voice.py
7
__init__.py
8
At:
JavaScript
1
2
1
C:Program FilesPython36Libsite-packagespyttsx3
2
And the contents of the file __init__.py
(I omitted comments):
JavaScript
1
13
13
1
from .engine import Engine
2
import weakref
3
4
_activeEngines = weakref.WeakValueDictionary()
5
6
def init(driverName=None, debug=False):
7
try:
8
eng = _activeEngines[driverName]
9
except KeyError:
10
eng = Engine(driverName, debug)
11
_activeEngines[driverName] = eng
12
return eng
13
Advertisement
Answer
It appears that the module pyttsx3 is not properly initialised. I hope you don’t have a file named pyttsx3.py anywhere in the module path. I found a related issue here.