1

I want to write a script which will read a list of words as it prints them to the screen.

import pyttsx

engine = pyttsx.init()
words = ["here","are","some","test","words"]

for i in words:
    engine.say(i)
    print i
    engine.runAndWait()

However, in running the above, all words other than "here" are cut short. I hear something like "here [pause] ar- so- te- wo-"

If I unindent engine.runAndWait(), the words are said after the loop is done. When I do this, they aren't cut off, but, of course, they aren't said at the at the same time they're printed.

I'm running Ubuntu 14.04.2

Charles Noon
  • 559
  • 3
  • 10
  • 16

2 Answers2

2

What you want is to print word, how about using callback, using pyttsx.Engine.connect?

import pyttsx


def cb(name):
    print(name)

engine = pyttsx.init()
engine.connect('started-utterance', cb)
for word in ["here", "are", "some", "test", "words"]:
    engine.say(word, name=word)

engine.runAndWait()
falsetru
  • 357,413
  • 63
  • 732
  • 636
1

This is a couple of years too late, but using engine.startLoop(False) and engine.iterate() following the "external event loop" example in the docs did the job for me.

import pyttsx
import time

engine = pyttsx.init()
words = ["here","are","some","test","words"]

engine.startLoop(False)
for i in words:
    engine.say(i)
    engine.iterate()
    print i
    while engine.isBusy(): # wait until finished talking
        time.sleep(0.1)

engine.endLoop()
Sharkovsky87
  • 133
  • 9