Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 程序在eclipse之外运行时不能完全工作_Python_Eclipse - Fatal编程技术网

Python 程序在eclipse之外运行时不能完全工作

Python 程序在eclipse之外运行时不能完全工作,python,eclipse,Python,Eclipse,我有一个小型python应用程序,它使用pyttsx进行一些文本到语音转换 工作原理: 只需说出剪贴板上的内容 该程序在eclipse中按预期工作。但是,如果在cmd.exe上运行,它只在剪贴板上的文本太大或太少的情况下部分工作。为什么? 从cmd运行时,它会打印语句,但如果剪贴板文本太大,实际的“对话”将无法工作 下面是实际执行对话的程序部分的一个示例:“对话”部分在线程中处理 def saythread(queue , text , pauselocation, startingPoint)

我有一个小型python应用程序,它使用pyttsx进行一些文本到语音转换

工作原理: 只需说出剪贴板上的内容

该程序在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\speechplay.py中运行程序的命令实际上,eclipse本身使用命令行命令启动其应用程序

您应该检查eclipse发出的启动程序的命令。这可能有点冗长,但您可以从这里开始,测试哪些是必要的,哪些不是

您可以通过运行程序,然后在调试窗口中选择输出来找出eclipse使用的命令行。右键单击它,选择属性,就完成了


如果你没有调试窗口,你可以打开它的窗口/显示视图/其他可能的/调试。

事实上,eclipse本身使用命令行命令来启动它的应用程序

您应该检查eclipse发出的启动程序的命令。这可能有点冗长,但您可以从这里开始,测试哪些是必要的,哪些不是

您可以通过运行程序,然后在调试窗口中选择输出来找出eclipse使用的命令行。右键单击它,选择属性,就完成了


如果没有调试窗口,可以打开它的窗口/show view/other mably/debug。

检查从剪贴板读取文本的代码是否存在问题

您应该检查eclipse设置是否为项目指定了eclipse外部不存在的自定义环境变量。特别是:

PYTHONPATH以及程序在设置中可能依赖的其他项目 路径 使用

在程序开始时比较两种设置

其他文体建议:

不要使用os.\u exit,更喜欢sys.exit您应该只在调用os.fork后在子进程中使用os.\u exit,这在Windows上不可用

我认为线程.Event比queue.queue更合适

对于带有方法的线程,我会使用子类方法,而不是带有内部函数的函数

例如:

import threading
import sys
import pyttsx

class SayThread(threading.Thread):

    def __init__(self, queue, text, pauselocation, startingPoint, debug=False):
        threading.Thread.__init__(self)
        self.queue = queue
        self.text = text
        self.pauselocation = pauselocation
        self.startingPoint = startingPoint
        self.pause = 0
        self.engine = pyttsx.init(debug=debug)
        self.pausequeue1 = False

    def run(self):
        if len(self.pauselocation) == 1:
            rate = self.engine.getProperty('rate')
            print rate
            self.engine.setProperty('rate', rate-30)
        textMod = self.text[self.startingPoint:]
        self.engine.say(self.text[self.startingPoint:])
        self.engine.connect("started-word", self.onWord )
        self.engine.connect("finished-utterance", self.onFinishUtterance )
        self.engine.startLoop(True)
        if self.pausequeue1 == False:
            sys.exit(1)

    def onWord(self, name, location, length):
        self.pausequeue1  = self.queue.get(False)
        self.pause = location
        self.pauselocation.append(location)
        if self.pausequeue1 == True :
            self.engine.stop()

    def onFinishUtterance(self, name, completed):
        if completed == True:
            sys.exit(0)


def runNewThread(wordsToSay, startingPoint):
    global queue, pauselocation
    t1 = SayThread(queue, wordsToSay,
                          pauselocation, startingPoint)
    t1.start()

#wordsToSay = CLIPBOARD CONTENTS
runNewThread(wordsToSay,0)

检查问题是否不在从剪贴板读取文本的代码中

您应该检查eclipse设置是否为项目指定了eclipse外部不存在的自定义环境变量。特别是:

PYTHONPATH以及程序在设置中可能依赖的其他项目 路径 使用

在程序开始时比较两种设置

其他文体建议:

不要使用os.\u exit,更喜欢sys.exit您应该只在调用os.fork后在子进程中使用os.\u exit,这在Windows上不可用

我认为线程.Event比queue.queue更合适

对于带有方法的线程,我会使用子类方法,而不是带有内部函数的函数

例如:

import threading
import sys
import pyttsx

class SayThread(threading.Thread):

    def __init__(self, queue, text, pauselocation, startingPoint, debug=False):
        threading.Thread.__init__(self)
        self.queue = queue
        self.text = text
        self.pauselocation = pauselocation
        self.startingPoint = startingPoint
        self.pause = 0
        self.engine = pyttsx.init(debug=debug)
        self.pausequeue1 = False

    def run(self):
        if len(self.pauselocation) == 1:
            rate = self.engine.getProperty('rate')
            print rate
            self.engine.setProperty('rate', rate-30)
        textMod = self.text[self.startingPoint:]
        self.engine.say(self.text[self.startingPoint:])
        self.engine.connect("started-word", self.onWord )
        self.engine.connect("finished-utterance", self.onFinishUtterance )
        self.engine.startLoop(True)
        if self.pausequeue1 == False:
            sys.exit(1)

    def onWord(self, name, location, length):
        self.pausequeue1  = self.queue.get(False)
        self.pause = location
        self.pauselocation.append(location)
        if self.pausequeue1 == True :
            self.engine.stop()

    def onFinishUtterance(self, name, completed):
        if completed == True:
            sys.exit(0)


def runNewThread(wordsToSay, startingPoint):
    global queue, pauselocation
    t1 = SayThread(queue, wordsToSay,
                          pauselocation, startingPoint)
    t1.start()

#wordsToSay = CLIPBOARD CONTENTS
runNewThread(wordsToSay,0)

原来pythonpath在我的系统上没有正确设置。
编辑:原来pythonpath不是问题所在。我不知道是什么问题。arghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh。
编辑:原来pythonpath不是问题所在。我不知道是什么问题。你说的跑步派对是什么意思?是否只处理了剪贴板中的部分文本,或其他内容?它将文本打印到标准输出,但不“说”任何内容?你说的“运行”是什么意思?是否只处理了剪贴板中的部分文本,或者其他内容?它将文本打印到STDOUT,但不会“说”eclipse正在使用python.exe-u file.py的任何内容。所以我试过了,但是我想exe和file.py的结果都是一样的?如果复制粘贴它会发生什么?是的,相同的路径。我粘贴了eclipse代码。好吧,这显然不是你的正确答案:抱歉,但这是我唯一想到的。好的eclipse使用的是python.exe-u file.py。所以我试过了,但是我想exe和file.py的结果都是一样的?如果复制粘贴它会发生什么?是的,相同的路径。我粘贴了日食代码。好吧,这显然不是你的正确答案:对不起,但这是我唯一想到的。