Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import pyttsx works in python 2.7, but not in python3

Question: why is python3 unable to find the engine module when importing pyttsx?

Details:

I'm doing this on a raspberry pi with Raspbian Wheezy

Under python 2.7, the following works:

>>> import pyttsx

Under python3, the following happens:

>>> import pyttsx
Traceback (etc...)
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python3.2/dist-packages/pyttsx-1.1-py3.2.egg/pyttsx/__init__.py", line 18, in <module>
ImportError: No module named engine

I've installed and used sudo pip install pyttsx

I've imported sys

sys.path contains this...

>>> print (sys.path) 
['','/usr/local/lib/python3.2/dist-packages/setuptools-5.4.1-py3.2.egg', '/usr/local/lib/python3.2/dist-packages/pyttsx-1.1-py3.2.egg', '/usr/lib/python3.2','usr/lib/python3.2/plat-linux2', '/usr/lib/python3.2/lib-dynload','/usr/local/lib/python3.2/dist-packages','/usr/lib/python3/dist-packages']

ls /usr/local/lib/python3.2/dist-packages results in...

easy-install.pth pyttsx-1.1-py3.2.egg setuptools-5.4.1-py3.2.egg setuptools.pth

unzip -t /usr/local/lib/python3.2/dist-packages/pyttsx-1.1-py3.2.egg shows....

pyttsx/__init__.py  OK
pyttsx/voice.py   OK
pyttsx/engine.py  OK
(etc...)
No errors detected in compressed data of pyttsx-1.1-py3.2.egg

Thanks for your help!

like image 563
mnr Avatar asked Jul 25 '14 20:07

mnr


People also ask

What is pyttsx3 in Python?

pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline and is compatible with both Python 2 and 3. An application invokes the pyttsx3.init () factory function to get a reference to a pyttsx3.

How to install pyttsx3 on PyCharm?

0. [Work on Mac] Pycharm --> Preference --> Project --> Python Interpreter --> click on a "+" symbol (down left corner) --> search "pyttsx3" (or any pip package) --> Install (It will take awhile but works) enter image description here. Share. Improve this answer.

Is win32com compatible with pyttsx3?

Unlike alternative libraries, it works offline, and is compatible with both Python 2 and 3. If you recieve errors such as No module named win32com.client, No module named win32, or No module named win32api, you will need to additionally install pypiwin32. Feel free to wrap another text-to-speech engine for use with pyttsx3.

How to convert text-into-speech using pyttsx3?

#firstly import pyttsx3 module to convert text-into-speech import pyttsx3 engine = pyttsx3.init () engine.say ('HERE PASS THE TEXT TO CONVERT INTO SPEECH') engine.runAndWait () Alternatively, you can use the pyttsx3 library to convert PDFs into audiobooks. The program is completely portable, and works offline without any delay.


2 Answers

I attempted to install pyttsx on Python 3.4 (on Windows). Here's what I discovered:

The pyttsx found on PyPi was developed by Peter Parente on GitHub.

Parente has abandoned further development, and never ported it to Python 3. I cannot even get his version to install on Python 3. I am not sure how you managed this.

A user called James Percent forked it and made a fairly minimal attempt to make it Python 3 compatible.

I found that attempt didn't go far enough, because - while I could install it and even import pyttsx successfully, when I tried to call pyttsx.init() it would do a dynamic import of a driver, and fail with an import error.

I made a further fork to fix that, which I will submit to James Percent. With those changes in place, I am able to run @Khanrad's test script.

like image 51
Oddthinking Avatar answered Sep 22 '22 21:09

Oddthinking


I believe you are looking for the library:

pyttsx3

This python3 compatible version is now packaged in pypi and works pretty well for both python2 and python3 and as far as i have tested , it didn't give any error.

just use :

pip install pyttsx3

Usage :

import pyttsx3
engine = pyttsx3.init()
engine.say("I am talking now ");
engine.setProperty('rate',100)  
engine.runAndWait();
like image 23
Natesh bhat Avatar answered Sep 23 '22 21:09

Natesh bhat