Free Text-to-Speech in Flash

There are several text-to-speech packages out there. But thanks to Google Translate, you can create a sort of "poor-man's" text-to-speech application in Flash. The method is a simple query string to the Google Translate service, which returns an MP3. Simply load that Mp3 into Flash, and voilà. The draw backs are that you only get on voice (although you can choose different languages which use an alternate accents) and you have a limit of 100 characters.

Check out the example and source code below.

import flash.events.MouseEvent;
import flash.media.Sound;
import flash.text.TextField;
import fl.controls.Button;
 
// stage instances
var input_txt:TextField;
var speak_btn:Button;
 
var speech:Sound;
var url:String = "http://translate.google.com/translate_tts?q=";
 
input_txt.maxChars = 100;
speak_btn.addEventListener(MouseEvent.CLICK, handleClick);
 
function handleClick(e:MouseEvent):void {
     speech= new Sound();
     speech.load(new URLRequest(url + input_txt.text));
     speech.play();
}

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.