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
  • What sort of back-end are you running? - you must have some sort of cgi configured with your server, otherwise it can only serve static documents. Here is an example on getting perl to work with it. – abolotnov Jan 21 '13 at 19:40
  • I used the instructions/config for lighttpd suggested in this answer: http://raspberrypi.stackexchange.com/questions/1346/how-to-get-python-to-work-with-lighttpd – HectorLector Jan 21 '13 at 21:12
  • 1
    so what's on the logs? can you copy/paste the code and how it's triggered? – abolotnov Jan 21 '13 at 22:15

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
  • 15
  • I was not able to test it yet (not time for playing :( ), but i think it was a proplem with the httpd daemon running as the wrong user. thanks. – HectorLector Feb 13 '13 at 07:46