as3 Text To Speech plus proxy
A while back I wrote a post on a few as3 classes I wrote that would hook into googles text to speech engine (you can view the original post here). Unfortunately there was a few problems with the way it worked, first and foremost not all browsers handled the cross domain sound request the same, as in IE/Chrome bitched about cross domain policy files. secondly there were some issues around using special characters (non english character sets)
I wasn’t using these classes in any commercial projects, so sadly these issues were never investigated, well that is until a chap by the name of Daniel Kazmer needed this type of functionality in one of his projects, I suggested looking into a proxy for the cross domain issues and that’s just what he did.
Click here to download the as3 text to speech classes as well as the proxy file Dan created (Note you’ll need php and curl installed to take advantage of the proxy).
While this is a step in the right direction it turns out there are still some issues surrounding special characters, but regardless thanks for your input Dan!
Read MoreTextToSpeech Accessibility
I recently posted a TextToSpeech as3 interface class which you can view here. Basically you pass it a string and it will read it out loud.
Today I’ve added an easy way to increase the accessibility of your flash microsite without having to go through the whole project adding code to every button. Simply add the two lines below to your root document and this class will search through every display object and add rollover text to speech.
1 2 3 | import ps.GText2Speech.Accessibility; var accessibility:Accessibility = new Accessibility(this); |
You can also specify to read the text on a click or rollout instead of the default rollover.
1 2 3 4 5 6 | import ps.GText2Speech.Accessibility; var accessibility:Accessibility = new Accessibility(this); accessibility.Rollover = false; accessibility.Click = true; accessibility.Rollout = true; |
In most cases there will probably be some textfields you want to ignore, so if you need to do this simply add the display object to the exclude list.
1 | accessibility.exclude(mc_skip); |
You can download the source and example files here.
If you fine any bugs or have any additional feature requests please post them below.
Enjoy!
Actionscript Text To Speech
Ever wanted to add text to speech functionality to your Actionscript project?
Well now you can thanks to this cool little as3 class I wrote last night.
So how does it work?
Google hasn’t released an official API for their text to speech engine, however if you query: http://translate.google.com/translate_tts?tl=en&q=this%20is%20a%20test an mp3 will be produced which speaks whatever q equals. There is however a limit to how many characters will be accepted in one query. TextToSpeech.as gets around this limitation by splitting your request up into smaller more manageable parts and then requests them one at a time. TextToSpeech.as also fixes the delay between clips on playback by starting playback of the next segment just before the current one finishes.
TextToSpeech.as simply bridges the gap between the Google text to speech engine and your as3 project. The example below imports TextToSpeech.as, loads a string (the first paragraph of this blog) and then plays it once the first segment has been converted and downloaded.
1 2 3 4 5 6 7 8 9 10 11 12 | import ps.GText2Speech.TextToSpeech; import ps.GTranslate.Language; textToSpeech = new TextToSpeech(); textToSpeech.Lang = Language.ENGLISH; textToSpeech.addEventListener("FirstClipLoaded", beginPlaying); textToSpeech.load('Ever wanted to add text to speech functionality to your Actionscript project? Well now you can thanks to Google and this awesome little as3 class I’ve written.'); function beginPlaying(event:Event):void { textToSpeech.play(); } |
Because TextToSpeech.as relies on the Google TextToSpeech engine it does mean that this could stop working in the future if Google decides to change or remove the URL. I guess the best way would be to actually do everything within actionscript, however this is easier said than done, so for the time being this is the best option we have.
You can download the source and example files here.
If anyone has additional feature requests please post them below.
Enjoy!
——————————————————
Update – Leading on from this post I’ve added a TextToSpeech accessibility class: Read More
——————————————————
Update – Seems to be a problem with the request within IE, not to sure what the problem is as I’m on a mac. I guess if you want to use this for a project it’d probably be a good idea to use a proxy on the same domain as your flash content.

Recent Comments