A conglomeration of Flash and other great things

Main menu

Post navigation

Text to Speech Fun

The possibilities for working with sound in ActionScript have been expanded with the relatively new SampleData event: you can now record sound from the microphone into a ByteArray or play sound dynamically from a ByteArray. This opens up the potential for all kinds of cool things, and I came across one example of this from Kelvin Luck, a class that plays back sounds at different speeds.

Also cool is the Google Translate text to speech webservice, which can be used to retrieve an mp3 file from a text query. Pete Shand circumvents the 100-character limit with his TextToSpeech class.

Combining these two I made a cool little application (just type in text, and press Hear): Vodpod videos no longer available.

While there are still a few little glitches, the potential is enormous. Something like this could be used for creating dynamic stories in games, where the text a user enters is actually spoken by a character, or….

There are still a few glitches in the code, but I’ll post it below. Thanks to Kelvin Luck and Pete Shand for the basis for the two sound classes – I only slightly changed them. If anyone would like to expand the code to include stuff like time-stretching and pitch-bending (also possible in ActionScript), that would be great too.

Update: Just saw that nerdook has used the google text to speech service in his most recent game: I Am An Insane Rogue AI, although not combined with adjusting its speed.