8

I want to play Google Text-To-Speech URL in Flash player on my webpage.

I am using http://www.alsacreations.fr/dewplayer.html but it doesn't work:

<object type="application/x-shockwave-flash" data="dewplayer.swf" width="200" 
        height="20" id="dewplayer" name="dewplayer">
<param name="wmode" value="transparent" />
<param name="movie" value="dewplayer.swf" />
<param name="flashvars" value="mp3=http://translate.google.com/translate_tts?q=hello-word&tl=en" />
</object>
Tomas
  • 57,621
  • 49
  • 238
  • 373
xkill
  • 107
  • 1
  • 9

2 Answers2

4

The URL of you MP3 file must be URL-Encoded (http://www.w3schools.com/tags/ref_urlencode.asp)

<object type="application/x-shockwave-flash" data="dewplayer.swf" width="200" height="20" id="dewplayer" name="dewplayer">
<param name="wmode" value="transparent" />
<param name="movie" value="dewplayer.swf" />
<param name="flashvars" value="mp3=http%3A%2F%2Ftranslate.google.com%2Ftranslate_tts%3Fq%3Dhello-world%26tl%3Den" />
</object>
Tchoupi
  • 14,560
  • 5
  • 37
  • 71
  • 1
    Google seems to have changed their API and added extra parameters. And this doesn't seem to work in another browser, they probably protect their content. You do realize that you cannot expect to use google TTL service in your own application / website, this is undoubtedly against their Terms and Conditions? – Tchoupi Apr 30 '12 at 14:16
  • This is an injustice, I wanted to make a wordpress plugin that I read the articles, using the voice of google. – xkill Apr 30 '12 at 14:31
  • Injustice? No. If you want to achieve that, you have to build your own application. Check out this PHP library for example: http://code.google.com/p/php-swift-tts/ – Tchoupi Apr 30 '12 at 14:48
4

I have made an intensive research and found some solutions. The conclusion made by Mathieu's (that google changes arguments and you have to write your own app) is wrong. The problem is that google checks for cross-domain access. It is not regulated via Adobe Flash player crossdomain.xml as in this case, surprisingly. Flash player doesn't attempt to load that file from server root directory (tested in Firebug).

The problem is that google is checking for referer, and if that is set, it refuses to load the content, please check:

So the problem boils down to referer spoofing for inline content.

Solution 1 - RefererKiller

You can use a simple trick: refer to the mp3 file in <img src=""> tag, see my example, with added referer spoofing. Then the flash player will not have to download it, since it will be in cache already. There are solutions to remove referer from inline content (see RefererKiller implementation for images). However, comment suggests the cross-browser compatibility might be an issue.

Solution 2 - https

So, the simplest solution is to use https protocol - clear your cache and try the above link with https added. Referer will not be set for inline content. But, if you don't have trusted certificate, you probably don't want your users to go through the terrible 4-click process to confirm the trust in your certificate. In that case, you probably want go for another solution.

Community
  • 1
  • 1
Tomas
  • 57,621
  • 49
  • 238
  • 373
  • [Additional reference](http://www.liens-du-vin.ch/playing-mp3-files.html) which summarizes some possibilities of embedding mp3 on a webpage. – Tomas Jun 09 '13 at 12:57