Create a Flash Speech Synthesizer
(Page 1 of 5 )
This hack uses Flash sound events to splice sound samples seamlessly together to simulate one continuous sound effect, in this case digitized speech using
allophones (phonetic speech sections from which the spoken word is built up). (Hack 52 from the book,
Flash Hacks, by Sham Bhangal, O'Reilly Media, 2004, ISBN: 0596006454.)
Synthesize speech for added flexibility with reduced bandwidth—no need to record or download predetermined sounds.
This hack uses Flash sound events to splice sound samples seamlessly together to simulate one continuous sound effect, in this case digitized speech using allophones (phonetic speech sections from which the spoken word is built up).
The Trouble with Lasers
Some hacks rely on standard techniques or technologies used for an unexpected application. Science is filled with unexpected uses of technologies, such as lasers. Few envisioned that lasers could be used for everything from warfare to surgery, to listen to music, watch movies, and transmit international phone conversations.
In this hack, we’ll see how the seemingly innocuous onSoundComplete event can be used to create a speech synthesizer in Flash.
Using Sound.onSoundComplete Event
As soon as the Sound.onSoundComplete( ) method came out in Flash MX, I thought, “Cool! We can now easily synchronize sound accurately enough to create a sound mixing board,” and sure enough, we can. The onSoundComplete event is accurate to a resolution of around 10 times the frame rate, so it’s far more accurate than the keyframe/onEnterFrame-based sound controls common in Flash 5.
Like all event-driven code, onSoundComplete events might be delayed if there is a lot of other stuff going on at the same time, particularly processor-intensive animation. Overtaxing the Flash Player may result in slight hitches (delays) in playback, so go easy!
Have a look at the following code (or have a look at the file groovyLoop.fla from this book’s web site):
function nextSound () {
myLoop.start();
}
myLoop = new Sound(this);
myLoop.attachSound("groovy");
myLoop.start();
myLoop.onSoundComplete = nextSound;
 | If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!
Visit the O'Reilly Network http://www.oreillynet.com for more online content. |
Next: Sound File >>
More Flash Articles
More By O'Reilly Media