3

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!

bensiu
  • 24,660
  • 56
  • 77
  • 117
Ankur
  • 81
  • 1
  • 2
  • 4

4 Answers4

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]))+" : ' ")
Joe Kington
  • 275,208
  • 71
  • 604
  • 463
Mugilan.M
  • 109
  • 2
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()
sleepynate
  • 7,926
  • 3
  • 27
  • 38
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?

Community
  • 1
  • 1
Michael Levy
  • 13,097
  • 15
  • 66
  • 100
  • 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 '11 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. – Michael Levy Apr 17 '11 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... – Joe Kington Apr 17 '11 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. – Joe Kington Apr 17 '11 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()
Marlon Abeykoon
  • 11,927
  • 4
  • 54
  • 75