4

I am new to this kind of programming which involves text to speech or speech to text conversion, that's why I am here for some initial help. I have searched over internet about it and I came across pyttsx for ubuntu, initially I could not get started with it but somehow I managed to do that but now the problem is that I type something like this:

import pyttsx
engine=pyttsx.init()

Its gives a segmentation fault. I need help on that and also tell me if I am using the right tool or not. Thanks in advance!

4 Answers 4

10

espeak is included in ubuntu by default. Try this one from python.

import os
import datetime

def tts(text):
      return os.system("espeak  -s 155 -a 200 "+text+" " )

m = datetime.datetime.now().strftime("%I %M %S")
tts("'Sir the time is"+str(int(m[0:2]))+" "+str(int(m[3:5]))+" : ' ")
6
$ sudo apt-get install sphinx2-bin libsphinx2-dev
# enter your password when prompted

$ python -i

>>> import pyttsx
>>> engine=pyttsx.init()
>>> engine.say('Sally sells seashells by the seashore.')
>>> engine.runAndWait()
3
  • Alternatively: sudo pip install pyttsx Nov 17, 2014 at 16:15
  • Does that actually install the libsphinx binaries & headers as well? I thought Sphinx was in C.
    – sleepynate
    Nov 18, 2014 at 20:06
  • I'm not too sure about it. Pip can also compile C, but I think I installed sphinx before. So I don't know if it would have worked if I hadn't installed it before. Nov 18, 2014 at 21:41
2

You might want to read over the answers in Need text to speech and speech recognition tools for Linux and Speech processing library in Python for speech to text

Why the segmentation fault? This is a a complete guess: you have the API package installed, but you do not have an actual speech engine (like Sphinx) installed. http://pypi.python.org/pypi/pyttsx says:

pyttsx is a Python package supporting common text-to-speech engines on Mac OSX, Windows, and Linux. It currently supports SAPI5, NSSpeechSynthesizer, and espeak. pyttsx requires Mark Hammond's win32com package on Windows.

Do you have one of the supported engines installed?

4
  • you are absolutely right I don't have any speech engine installed on my system and I don't even have the pyttsx API installed on my system. Rather I simply downloaded the pyttsx package, moved to that directory and imported the pyttsx directory.Tell me how to install the API.
    – Ankur
    Apr 17, 2011 at 15:09
  • Sorry. I gave you everything I got on that subject. I can help you with Windows packages, but for Ubuntu, you've reached the limits of my knowledge. Apr 17, 2011 at 15:11
  • @Ankur - Try installing espeak. If that fixes the problem, you might also let the package maintainers for pyttsx on ununtu know that the dependencies for their .deb package are broken. Given that you're getting a segfault, its likely another problem, though... Apr 17, 2011 at 15:29
  • 1
    @Ankur - Wait, did you actually try to build the pyttsx module? Just "moving to that directory and importing the pyttsx directory" only (ever) works in the case of pure-python modules. Either install pyttsx from a repo in the usual manner (as @sleeypnate suggested above) or build and install the python module as you normally would using setuptools (e.g. either python setup.py build && sudo python setup.py install or sudo easy_install pyttsx). If you build it, though, you'll need the full build dependencies. You're much better off installing it from the repos. Apr 17, 2011 at 18:52
-1
import pyttsx
engine = pyttsx.init()
engine.setProperty('rate', 75)
for voice in voices:
    print "Using voice:", repr(voice)
    engine.setProperty('voice', voice.id)
    engine.say("How are you doing")

engine.runAndWait()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.