Problem with pyttsx

1

I am trying to work with the pyttsx module. I read the documentation and followed everything to the letter. However, when I try to run a script as simple as this:

import pyttsx
engine = pyttsx.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()

Launches an error that is as follows:

  

ModuleNotFoundError: No module named 'engine'

Install the module in a virtual environment. So I went to the folder where it is housed in the module code. Alli has its script init in it the engine module is imported in the following way

  

from engine import Engine

You are importing the Engine class that is hosted on engine. However he does not let me run the script because he can not find this module. Check already and are even at the same level. I appreciate your help.

    
asked by limg21 20.07.2017 в 22:57
source

3 answers

4

The module pyttsx is under-maintained by what it seems, the latest version in pypi is 1.1 of 2012 (although it seems that there is a more recent version according to the documentation, 1.2 of 2015) and is written in Python 2.

Possibly fixing the import in the source code can be made to work. You can also use Python 2, but it is preferable to carry all the code from Python 2 to Python 3 given the more than the next death of branch 2 (if nothing changes for the PyCon 2020 will stop supporting Python 2). In any case the module is still quite outdated.

There is a recent and maintained fork for Python 3 / Python 2 which is what you should consider using pyttsx3:

link

Its handling is assumed to be identical to pyttsx (although I have never used the latter). I have used pyttsx3 before and it works perfectly in Python 3.6 and 3.5 which is where I tried it. Your code does not change anything, just the name of the module:

import pyttsx3
engine = pyttsx3.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
    
answered by 20.07.2017 в 23:25
2

Looking a bit at the code it seems that pyttsx only works for the versions of Python 2, if you have no problems in using that version of Python I suggest you create your virtual environment using that version:

$ virtualenv --python='which python2' venv
Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/cesar/venv/bin/python2
Also creating executable in /home/cesar/venv/bin/python
Installing setuptools, pip, wheel...done.
$ source venv/bin/activate
(venv) $ pip install pyttsx
Collecting pyttsx
Installing collected packages: pyttsx
Successfully installed pyttsx-1.1
(venv) $ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyttsx
>>> 

Run without problems.

    
answered by 20.07.2017 в 23:25
1

sudo apt-get install python-espeak

that's all you need ... the same thing happened to me

    
answered by 14.03.2018 в 03:37