This is not a duplicate of subprocess.Popen: 'OSError: [Errno 13] Permission denied' only on Linux as that problem occurred due to wrong permissions. That has been fixed and this is an entirely different problem.
当我的代码(如下所示)在Windows(我的笔记本电脑和AppVeyor CI)上执行时,它会做它应该做的事情。但是在Linux(TravisCI上的VM)上,它会抛出一个文件未找到错误。在
我正在/home/travis/build/sayak-brm/espeak4py/中执行。在
ls -l输出:$ ls -l
total 48
-rw-rw-r-- 1 travis travis 500 Sep 29 20:14 appveyor.yml
drwxrwxr-x 3 travis travis 4096 Sep 29 20:14 espeak4py
-rw-rw-r-- 1 travis travis 32400 Sep 29 20:14 LICENSE.md
-rw-rw-r-- 1 travis travis 2298 Sep 29 20:14 README.md
-rw-rw-r-- 1 travis travis 0 Sep 29 20:14 requirements.txt
-rw-rw-r-- 1 travis travis 759 Sep 29 20:14 test.py
$ ls -l espeak4py
total 592
-rwxr-xr-x 1 travis travis 276306 Sep 30 06:42 espeak
drwxrwxr-x 5 travis travis 4096 Sep 29 20:14 espeak-data
-rw-rw-r-- 1 travis travis 319488 Sep 29 20:14 espeak.exe
-rw-rw-r-- 1 travis travis 1125 Sep 29 20:14 __init__.py
$ ls -l /home/travis/build/sayak-brm/espeak4py/espeak4py
total 592
-rwxr-xr-x 1 travis travis 276306 Sep 30 06:42 espeak
drwxrwxr-x 5 travis travis 4096 Sep 30 06:42 espeak-data
-rw-rw-r-- 1 travis travis 319488 Sep 30 06:42 espeak.exe
-rw-rw-r-- 1 travis travis 1216 Sep 30 06:42 __init__.py
这表明这些文件在它们应该在的地方。在
espeak文件是Linux ELF二进制文件。在
错误:
^{pr2}$
代码:
espeak4py/__init__.py:#! python3
import subprocess
import os
import platform
class Speaker:
"""
Speaker class for differentiating different speech properties.
"""
def __init__(self, voice="en", wpm=120, pitch=80):
self.prevproc = None
self.voice = voice
self.wpm = wpm
self.pitch = pitch
if platform.system() == 'Windows': self.executable = os.path.dirname(os.path.abspath(__file__)) + "/espeak.exe"
else: self.executable = os.path.dirname(os.path.abspath(__file__)) + "/espeak"
def generateCommand(self, phrase):
cmd = [
self.executable,
"--path=.",
"-v", self.voice,
"-p", self.pitch,
"-s", self.wpm,
phrase
]
cmd = [str(x) for x in cmd]
return cmd
def say(self, phrase, wait4prev=False):
cmd=self.generateCommand(phrase)
if wait4prev:
try: self.prevproc.wait()
except AttributeError: pass
else:
try: self.prevproc.terminate()
except AttributeError: pass
self.prevproc = subprocess.Popen(cmd, executable=self.executable, cwd=os.path.dirname(os.path.abspath(__file__)))
test.py:#! python3
import espeak4py
import time
print('Testing espeak4py\n')
print('Testing wait4prev')
mySpeaker = espeak4py.Speaker()
mySpeaker.say('Hello, World!')
time.sleep(1)
mySpeaker.say('Interrupted!')
time.sleep(3)
mySpeaker.say('Hello, World!')
time.sleep(1)
mySpeaker.say('Not Interrupted.', wait4prev=True)
time.sleep(5)
print('Testing pitch')
myHighPitchedSpeaker = espeak4py.Speaker(pitch=120)
myHighPitchedSpeaker.say('I am a demo of the say function')
time.sleep(5)
print('Testing wpm')
myFastSpeaker = espeak4py.Speaker(wpm=140)
myFastSpeaker.say('I am a demo of the say function')
time.sleep(5)
print('Testing voice')
mySpanishSpeaker = espeak4py.Speaker(voice='es')
mySpanishSpeaker.say('Hola. Como estas?')
print('Testing Completed.')
我不明白为什么它只在一个平台上工作,而在另一个平台上不起作用。在