當 Flash 使用 google translate API - "http://translate.google.com/translate_tts" 時, 如果用 FireFox 以外的Browser 會有 Proxy 問題, 導致讀取 "http://translate.google.com/translate_tts"時, 變了 404 Error
在 Flash run in browser 時會拋出 Stream Error #2032
解決方法:
開一個 php File (translate.php), 寫以下 Code,
$url = $_POST["url"];
$content = file_get_contents($url);
echo $content;
AS3:
var url:String="http://translate.google.com/translate_tts?tl=en&" + "q=" +encodeURI(_input.text);
req = new URLRequest(url);
var urlRequest:URLRequest = new URLRequest("translate.php");
var urlLoader:URLLoader = new URLLoader();
var urlVars:URLVariables = new URLVariables();
urlVars.url = url;
urlRequest.data = urlVars;
urlRequest.method = URLRequestMethod.POST;
snd = new Sound();
snd.addEventListener(Event.COMPLETE, onComplete);
snd.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
// 讀取 php 從Google取回來的Sound Data
snd.load(urlRequest);
参考:
http://blog.onebyonedesign.com/actionscript/googles-text-to-speech-engine-in-flash/