windows 10-64bit
I'm trying to use some text-to-speech tool to read text from lines of .txt document, something like this:
so with pyttsx:
import pyttsx
engine = pyttsx.init()
engine.say('my voice')
engine.runAndWait()
I got this error:
Traceback (most recent call last):
File "...", line 1, in <module>
import pyttsx
File "/.../pyttsx/__init__.py", line 18, in <module>
from engine import Engine
ImportError: No module named 'engine'
now gTTS, available as gtts_token, so how to use it? because this way module is unrecognizable:
import gtts
blabla = ("my voice")
tts = gtts.gTTS(text=blabla, lang='en')
tts.save("C:/rec.mp3")
or:
from gtts import gTTS
blabla = ("my voice")
tts = gTTS(text=blabla, lang='en')
tts.save("C:/rec.mp3")
error:
import gtts
ImportError: No module named 'gtts'
also I'm want try to use espeak but not sure how to install it, is it available with pip install or I have to install it some other way to try it:
import subprocess
text = '"my voice"'
subprocess.call('espeak '+text, shell=True)
or:
import os
os.system("espeak 'my voice'")
so I'm trying to find some solution, but everything I tried is not working here...
for python3 use
pyttsx3
Its a new library compatible with both python3 and python2. Unlike gTTS it doesn't need internet connection and there is no delay in the sound produced.
Install:
pip install pyttsx3
Usage :
I am using windows 10 and Python 2.7.
For pyttsx:
Below code is working fine for me. I did get
ImportError: No module named win32api
error for which I had to install win32api from hereAfter that I could play "my voice". Although the quality and fidelity of spoken sound was very low.
gtts
is much better in that regards.For the error you are getting, Can you look into your python folder and see if
engine.py
file is present?For e.g. in my case, I've
pyttsx
modules installed at following locationC:\Python27\Lib\site-packages\pyttsx
and here is a list of files,Since import of
engine
is failing, I am wondering if you haveengine.py
file in the correct folder or present at all.For gtts:
I tried playing sound with
winsound
, but it did not work. Usingpydub
I was able to play theaudio file
. But, since your requirement is not to use a file, this may be a moot point.Hope this helps.
I'm using python2.7 on Ubuntu.
Try to replace "from engine import Engine" with "from .engine import Engine" in the engine module.It work for me!