0

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.

When my code (given below) executes on Windows (both my laptop and AppVeyor CI), it does what it's supposed to do. But on Linux (VM on TravisCI), it throws me a file not found error.

I am executing in /home/travis/build/sayak-brm/espeak4py/.

ls -l outputs:

$ 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

which shows that the files are where they are supposed to be.

The espeak file is a Linux ELF Binary.


Error:

$ python3 test.py
Testing espeak4py
Testing wait4prev
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    mySpeaker.say('Hello, World!')
  File "/home/travis/build/sayak-brm/espeak4py/espeak4py/__init__.py", line 38, in say
    self.prevproc = subprocess.Popen(cmd, executable=self.executable, cwd=os.path.dirname(os.path.abspath(__file__)))
  File "/opt/python/3.2.6/lib/python3.2/subprocess.py", line 744, in __init__
    restore_signals, start_new_session)
  File "/opt/python/3.2.6/lib/python3.2/subprocess.py", line 1394, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 2] No such file or directory: '/home/travis/build/sayak-brm/espeak4py/espeak4py/espeak'

Code:

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.')

I don't understand why it works only on one platform and not the other.

Travis CI Logs: https://travis-ci.org/sayak-brm/espeak4py

AppVeyor Logs: https://ci.appveyor.com/project/sayak-brm/espeak4py

GitHub: https://sayak-brm.github.io/espeak4py

Community
  • 1
  • 1
sbrm1
  • 1,195
  • 3
  • 12
  • 25
  • Once again you have `-rw-rw-r--`... Can you show `ls -l espeak4py` after the `chmod`? – zvone Sep 30 '16 at 06:43
  • Oh, I copied from the previous question and forgot to change it. – sbrm1 Sep 30 '16 at 06:44
  • Changed and also added output of `$ ls -l /home/travis/build/sayak-brm/espeak4py/espeak4py`. – sbrm1 Sep 30 '16 at 06:46
  • Now it looks interesting :) – zvone Sep 30 '16 at 06:54
  • I'll test it on Bash for Windows tomorrow. – sbrm1 Oct 01 '16 at 03:32
  • What's the content of the `espeak` file? "No such file or directory" is sometimes also thrown when a script has an invalid shebang line. – tripleee Oct 10 '16 at 19:36
  • Possible duplicate of [subprocess.Popen: 'OSError: \[Errno 13\] Permission denied' only on Linux](http://stackoverflow.com/questions/39777345/subprocess-popen-oserror-errno-13-permission-denied-only-on-linux) – tripleee Oct 10 '16 at 19:39
  • @tripleee No, that's not a duplicate, its an entirely different issue and I know that because I asked bothe the questions. – sbrm1 Oct 13 '16 at 09:21
  • @tripleee The `espeak` file is a linux ELF binary file with correct permissions. – sbrm1 Oct 13 '16 at 09:22
  • 1
    Then you should explain how this is different from your previous question. I see now that they are different but a superficial inspection would suggest otherwise. Just clarify in order to keep out duplicate votes. – tripleee Oct 13 '16 at 09:45
  • If you are sure it is a correct ELF binary, please [edit] the question to clarify this. Output from `file` would be helpful to prove this. – tripleee Oct 13 '16 at 09:46
  • @tripleee The binary by itself works from bash, but I cannot run it from Python. As for the output, it produces audio but does not output anything to `stdout`. – sbrm1 Oct 13 '16 at 10:47
  • How do you know it's correct for the host where Travis runs? It could be a different architecture. Again, please include *proof* in the question that you have checked this adequately, not just your say-so. – tripleee Oct 13 '16 at 10:51

2 Answers2

0

I've tested your espeak Python wrapper on Linux, and it works for me. Probably it's just an issue with Windows trailing \r characters. You could try the following:

sed -i 's/^M//' espeak4py/__init__.py

To enter the ^M, type Ctrl-V followed by Ctrl-M, and see if running that sed command solves the issue.

Mauro Lacy
  • 389
  • 2
  • 8
  • What is the escape char/Unicode name for `^M`. Actually my primary development platform is Windows since the hard-drive on my linux box crashed... Even the hexcode for the character will do. `Ctrl-V` is the shortcut for paste here on windows – sbrm1 Oct 13 '16 at 10:57
  • Weird. You should try editing the files on Linux, and/or saving them with the Linux file format (only `\n` at the end.) Also, for completeness try `sed -i 's/\r//g' espeak4py/__init__.py` – Mauro Lacy Oct 13 '16 at 11:05
  • The line endings in that file are `[CR][LF]` (`0x0D, 0x0A`), don't know what's that though. The way the file is organized should not cause a problem, or so I believe. – sbrm1 Oct 13 '16 at 11:06
  • 1
    Yes, but, it strikes me that your code worked for me at the first try. – Mauro Lacy Oct 13 '16 at 11:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/125588/discussion-between-sbrm1-and-mauro-lacy). – sbrm1 Oct 13 '16 at 11:09
0

The Linux binary packaged with the repo is not compatible with the Travis Build Architecture and the binary needs t be built from source before it is executed.

Instructions for buiding: https://github.com/rhdunn/espeak#building-1

sbrm1
  • 1,195
  • 3
  • 12
  • 25