pyttsx - 循环使 runAndWait() 中断
pyttsx - loop makes runAndWait() cut off
我想编写一个脚本来读取单词列表并将它们打印到屏幕上。
import pyttsx
engine = pyttsx.init()
words = ["here","are","some","test","words"]
for i in words:
engine.say(i)
print i
engine.runAndWait()
然而,在上面的运行中,除"here"之外的所有单词都被缩短了。我听到类似 "here [pause] ar- so- te- wo-"
的声音
如果我取消缩进engine.runAndWait()
,这些词会在循环完成后说出。当我这样做时,它们不会被切断,但是,当然,它们不会在打印的同时被说出来。
我是 运行 Ubuntu 14.04.2
你要的是打印word,用callback怎么样,用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()
这已经晚了几年,但是按照 docs 中的 "external event loop" 示例使用 engine.startLoop(False)
和 engine.iterate()
为我完成了工作。
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()
我想编写一个脚本来读取单词列表并将它们打印到屏幕上。
import pyttsx
engine = pyttsx.init()
words = ["here","are","some","test","words"]
for i in words:
engine.say(i)
print i
engine.runAndWait()
然而,在上面的运行中,除"here"之外的所有单词都被缩短了。我听到类似 "here [pause] ar- so- te- wo-"
的声音如果我取消缩进engine.runAndWait()
,这些词会在循环完成后说出。当我这样做时,它们不会被切断,但是,当然,它们不会在打印的同时被说出来。
我是 运行 Ubuntu 14.04.2
你要的是打印word,用callback怎么样,用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()
这已经晚了几年,但是按照 docs 中的 "external event loop" 示例使用 engine.startLoop(False)
和 engine.iterate()
为我完成了工作。
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()