Pyttsx And Gtts Module Errors
Solution 1:
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 :
importpyttsx3engine= pyttsx3.init()
engine.say("Hi this is working ");
engine.setProperty('volume',0.9)
engine.runAndWait()
Solution 2:
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 here
After that I could play "my voice". Although the quality and fidelity of spoken sound was very low. gtts
is much better in that regards.
importpyttsxengine= pyttsx.init()
engine.say('my voice')
engine.runAndWait()
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 location
C:\Python27\Lib\site-packages\pyttsx
and here is a list of files,
Name
----
drivers
driver.py
driver.pyc
engine.py
engine.pyc
voice.py
voice.pyc
__init__.py
__init__.pyc
Since import of engine
is failing, I am wondering if you have engine.py
file in the correct folder or present at all.
For gtts:
I tried playing sound with winsound
, but it did not work. Using pydub
I was able to play the audio file
. But, since your requirement is not to use a file, this may be a moot point.
import gtts
import winsound
from pydub import AudioSegment
from pydub.playback import play
blabla = ("my voice")
tts = gtts.gTTS(text=blabla, lang='en')
tts.save("rec.mp3")
print"Playing sound .."#winsound.PlaySound("rec.wav", winsound.SND_FILENAME)
song = AudioSegment.from_mp3("rec.mp3")
play(song)
Hope this helps.
Solution 3:
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!
Post a Comment for "Pyttsx And Gtts Module Errors"