0

I've made a html file and a python script to control my raspberry pi GPIO pins via websocket with the Tornado Web Server. It works great. To serve my static html page I use the following code in the python script:

application = tornado.web.Application([
    (r'/escape/media/(.*)',tornado.web.StaticFileHandler,{"path":'/home/pi/myproject/media'}),
    (r'/escape/(.*)',tornado.web.StaticFileHandler,{"path":'/home/pi/myproject'}),
    (r'/mycode',WSHandler)
])
if __name__ == "__main__":
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(8888)
    print 'Websocket Server Start ...'
    tornado.ioloop.IOLoop.instance().start()

In the html file I try to load an external mp3 file to play:

function talk() {
            text = encodeURI(document.getElementById("textinput").value);
            mp3 = new Audio('http://translate.google.com/translate_tts?tl=en&q=' + text);
            mp3.play();
        }

This works if I load the webpage from my own disk on my windows machine but not when Tornado servers it as a static page from the raspberry pi. In the javascript console I get the message: "Failed to load resource: the server responded with a status of 404 (Not Found)".

I don't understand why this is a problem because it's an absolute link to an external website. Does anyone know the solution?

Thanks!

Oehoe
  • 49
  • 1
  • 1
  • 7

1 Answers1

0

It looks like the problem is that Google is blocking the use of this API based on the Referer header. When the file is on local disk no Referer is sent and it works, but when the file is accessed over HTTP the Referer is sent and Google returns a 404. See Request to Google Text-To-Speech API for more details including possible workarounds.

Community
  • 1
  • 1
Ben Darnell
  • 21,844
  • 3
  • 29
  • 50
  • Thanks for your answer. I'm going to look into the workarounds and see if I can fix it that way. – Oehoe Apr 16 '15 at 20:27