我有一個小型的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」是什麼意思?只是處理剪貼板中的文本的一部分,還是其他內容? –
它將文本打印到標準輸出,但不'說'任何東西 –