as3 Text To Speech plus proxy

A while back I wrote a post on a few as3 classes I wrote that would hook into googles text to speech engine (you can view the original post here). Unfortunately there was a few problems with the way it worked, first and foremost not all browsers handled the cross domain sound request the same, as in IE/Chrome bitched about cross domain policy files. secondly there were some issues around using special characters (non english character sets)

Get Adobe Flash player

I wasn’t using these classes in any commercial projects, so sadly these issues were never investigated, well that is until a chap by the name of Daniel Kazmer needed this type of functionality in one of his projects, I suggested looking into a proxy for the cross domain issues and that’s just what he did.

Click here to download the as3 text to speech classes as well as the proxy file Dan created (Note you’ll need php and curl installed to take advantage of the proxy).

While this is a step in the right direction it turns out there are still some issues surrounding special characters, but regardless thanks for your input Dan!

8 Comments

  1. Great stuff, it works on the server where I tested it. But I’m worriedhaving an open proxy script like that is a security risk – how could I update the proxy script to only work whn called from a particular SWF file?

  2. haha, hope you see the irony in your question… If you don’t add an open cross domain file to your domain and someone tries to use your domain to do the text to speech it’ll behave exactly the same as the google url (as in it’ll probably work in firefox, but not ie or chrome) but then they could just use a proxy themselves. It’d make more sense for them to cut your domain out of the equation all together and go straight to the source though.

    I’m not 100% sure about this, but you might be able to add something to your php proxy to detect if the request is coming from the same domain, if it is, return as normal, if not reject:

    //if example.com is there in HTTP_REFERRER variable if(strpos($_SERVER[‘HTTP_REFERER’],’example.com’))
    {
    //only process operation here
    }

  3. You’re very welcome. I appreciate the credit. And if anyone solves the ‘special characters’ issue, I would love to hear about it!

  4. This is the definitive proxy with special chars support!
    I’m sure it can simplified a bit, but voila!
    My source of inspiration: http://stackoverflow.com/questions/713293/php-file-get-contents-encoding-problem-solved
    array(
    ‘method’ => ‘POST’,
    ‘header’ => implode(“\r\n”, array(
    ‘Content-type: application/x-www-form-urlencoded’,
    ‘Accept-Language: en-us,en;q=0.5’, // optional
    ‘Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7’ // optional
    )),
    ‘content’ => http_build_query(array(
    ‘prev’ => ‘_t’,
    ‘hl’ => ‘en’,
    ‘ie’ => ‘UTF-8’,
    ‘text’ => ‘hello’,
    ‘sl’ => ‘en’,
    ‘tl’ => $lang[0] //’hu’
    ))
    )
    ));
    echo file_get_contents($url, FILE_TEXT, $context);
    ?>

  5. hmm. post became truncated. weird.

  6. Not familiar with proxies. How do you use it?

  7. our good friend google should be able to shed some light on proxies

  8. Well, I got it to work with portuguese language (Accents problems).


    array(
    'method' => 'POST',
    'header' => implode("\r\n", array('Content-type: application/x-www-form-urlencoded')),
    'content' => http_build_query(array('prev' => '_t',
    'hl' => 'en',
    'ie' => 'UTF-8',
    'sl' => 'en',
    'tl' => 'pt-BR'))
    )
    ));

    $q = urlencode($url);
    $page = file_get_contents($url, FILE_TEXT, $context);

    header("Content-Type: audio/mpeg");
    echo $page;
    ?>

Trackbacks/Pingbacks

  1. Actionscript Text To Speech | Pete Shand - […] —————————————————— Update – you can read more about using a proxy here. […]

Submit a Comment

Your email address will not be published. Required fields are marked *