Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

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
share|improve this question
    
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: raspberrypi.stackexchange.com/questions/1346/… –  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
add comment

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 7:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.