2007/08/21

文字转换为声音


看到一个有趣的日文 API ,可以把文字转换为声音,刚好有人在试验,我把它改成了可以输入文字的形式。以前在学校的时候,某某同学总是用刚学来的叨不叨不的日语跟我说“男人很辛苦”,我试着输入“男人很辛苦”,“男人”好像是这么说的,辛苦好像用中文说的。这个东西没事可以用来查查某些日语。
代码如下(未经整理的):
package {
import
fl.controls.Button;
import
flash.display.*;
import
flash.events.*;
import
flash.net.*;
import
flash.media.Sound;
import
flash.media.SoundChannel;
import
flash.text.TextField;
import
flash.text.TextFieldType;
import
flash.events.TextEvent;
public class
Text2speech01 extends Sprite {
private
const API_URL:String = "http://api.satoru.net/text2voice/";
private var
urlReq:URLRequest = new URLRequest(API_URL);
private var
urll:URLLoader = new URLLoader();
private var
v:URLVariables = new URLVariables();
public var
textInputTxt:TextField;
function
Text2speech01() {
init();
}

private function
init():void {
var
myButton:Button = new Button();
textInputTxt = new TextField();
textInputTxt.addEventListener(TextEvent.TEXT_INPUT, textInputHandler);
textInputTxt.type = TextFieldType.INPUT;
textInputTxt.background = true;
textInputTxt.border = true;
textInputTxt.height=20;
textInputTxt.width=300;
textInputTxt.x=10;
textInputTxt.y=18;
textInputTxt.text="Long long ago, there is a girl."
v.text = "Long long ago, there is a girl.";
addChild(textInputTxt);
myButton.label = "saying";
//myButton.emphasized = true;
myButton.width = 80;
myButton.move(10, 50);
addChild(myButton);
myButton.addEventListener(MouseEvent.CLICK, buttonClick);
textInputTxt.addEventListener(MouseEvent.MOUSE_OVER,changeStyle1);
textInputTxt.addEventListener(MouseEvent.MOUSE_OUT,changeStyle2);
}

private function
changeStyle1(e:MouseEvent):void{
textInputTxt.borderColor= 0x00FF00;
}

private function
changeStyle2(e:MouseEvent):void{
textInputTxt.borderColor= 0x000000;
}

private function
textInputHandler(e:TextEvent):void {
v.text= textInputTxt.text+e.text;
//trace(">> e.text: " + e.text);
//trace(">> textInputTxt.text: " + v.text);
}
private function
buttonClick(e:MouseEvent) {
urlReq.data = v;
urlReq.method = URLRequestMethod.GET;
trace
("urlReq is :"+urlReq.data);
urll.load(urlReq);
urll.addEventListener(Event.COMPLETE, function(e:Event):void {
trace
("API COMPLETE : " + urll.data);
var
sreq:URLRequest = new URLRequest(urll.data);
var
sf:Sound = new Sound();
sf.addEventListener(Event.COMPLETE, function(e:Event):void {
trace
("Sound load COMPLETE");
});

sf.load(sreq);
var
sc:SoundChannel = sf.play();

sc.addEventListener(Event.SOUND_COMPLETE, function(e:Event):void {
trace
("Sound play COMPLETE");
});

});
}
}
}

Labels: ,

1 Comments:

Blogger sike said...

远程的好像有个 bug ,待处理。

August 22, 2007 12:07 AM  

Post a Comment

Links to this post:

Create a Link

<< Home