我有一个小型的python应用程序,它使用pyttsx来处理某些文本到语音。在eclipse外部运行时,程序无法完全运行
它是如何工作的: 只需说出剪贴板中的任何内容。
该程序在eclipse中按预期工作。但是,如果在cmd.exe上运行,它只会在剪贴板上的文本太大(几段)时才起作用。为什么?
从CMD运行时,它打印报表,但实际的“说话”不工作(如果剪贴板文本太大
这是一个实际上不说话的程序部分的:正如可以看出,“说话”的部分是一个线程中处理
def saythread(queue , text , pauselocation, startingPoint):
saythread.pauselocation = pauselocation
saythread.pause = 0
saythread.engine = pyttsx.init()
saythread.pausequeue1 = False
def onWord(name, location, length):
saythread.pausequeue1 = queue.get(False)
saythread.pause = location
saythread.pauselocation.append(location)
if saythread.pausequeue1 == True :
saythread.engine.stop()
def onFinishUtterance(name, completed):
if completed == True:
os._exit(0)
def engineRun():
if len(saythread.pauselocation) == 1:
rate = saythread.engine.getProperty('rate')
print rate
saythread.engine.setProperty('rate', rate-30)
textMod = text[startingPoint:]
saythread.engine.say(text[startingPoint:])
token = saythread.engine.connect("started-word" , onWord)
saythread.engine.connect("finished-utterance" , onFinishUtterance)
saythread.engine.startLoop(True)
engineRun()
if saythread.pausequeue1 == False:
os._exit(1)
def runNewThread(wordsToSay, startingPoint):
global queue, pauselocation
e1 = (queue, wordsToSay, pauselocation, startingPoint)
t1 = threading.Thread(target=saythread,args=e1)
t1.start()
#wordsToSay = CLIPBOARD CONTENTS
runNewThread(wordsToSay,0)
感谢
编辑:我已经检查比使用的Python版本是相同的2.7用于在cmd中运行该程序的命令: python d:\python\play\speech\speechplay.py
“run party”是什么意思?只是处理剪贴板中的文本的一部分,还是其他内容? –
它将文本打印到标准输出,但不'说'任何东西 –