在 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/
hello
回覆刪除Please, Can you give me your "translate.php" file because it does not work for me. I did exactly the same. thank you