使用百度或谷歌服务将文字转语音


private function test():void
{
var request:URLRequest = new URLRequest();

var str:String = "从前有座山,山上有座庙,庙里有个老和尚";

var url:String = "http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=" + str; // baidu
url = "http://translate.google.cn/translate_tts?ie=UTF-8&tl=zh-CN&total=1&idx=0&textlen=19&prev=input&q=" + str; // google
request.url = encodeURI(url);
request.contentType = "audio/mp3"; // for baidu
request.contentType = "audio/mpeg"; // for google

var sound:Sound = new Sound(request);
sound.play();
}

你可能感兴趣的:(Flex示例)