1

I am running lighttpd webserver on my raspberry pi (raspbian os). On my small website I have a form which executes a python script via cgi - this part is working okay. Now I tried to call espeak from python:

os.system('espeak "hallo" ')

When I execute the script directly it works fine and says "hello" (ove hdmi / TV if that matters), but when I try to start the script over the website it is not working.

I guess it has something to do with permissions, other os.system() calls work fine. Using espeak is not necessary, any text-to-speech system will do. Thanks.

Edit for better understanding:

I have this html form

<form action="/cgi-bin/test.py">
  <input type="submit" value="PythonTest" /><br>
</form>

and in the test.py:

#!/usr/bin/python

import cgi,os,cgitb,sys
cgitb.enable()
sys.path.insert(0, "/usr/bin/espeak")


def say(something):
        os.system('sudo espeak  "{0}"'.format(something))

print "Yeah, Python!"

res = os.system("ls -l")
res1 = say("hallo")

print "end"

the error log of lighttpd is empty and also cgitb is showing no error. The Sound is just not playing. The output is:

Yeah, Phyton!
<ls output>
None
end
HectorLector
  • 158
  • 7

1 Answers1

1

Are you running your httpd daemon with pi priveleges?

sys.path.insert(0, "/usr/bin/espeak")

this line above doesn't help anything - you are inserting /usr/bin/espeak into your syspath - what gives? You might want to ether insert/append /usr/bin instad and keep your os.system method calling espeak or not play with the sys.path and call espeak as /usr/bin/espeak.

However, I'd convert your say method into somewhat like this to prevent possible error output supression:

def say(something):
    try:
        os.system('sudo espeak  "{0}"'.format(something))
        print('Hello?')
    except Exception as e:
        print(e.message)

using sudo command as part of CGI is however not safe I am sure you are aware and only using this to prototype. In your case I guess you could have done this:

chmod +x /usr/bin/espeak

and thus removing the need for sudo, however, apps in /usr/bin mostly appear as runnable by all.

abolotnov
  • 952
  • 1
  • 7
  • 16