O'Reilly logo

Learning ActionScript 3.0 by Zevan Rosser, Rich Shupe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with Microphone Sound

It is also possible to access some information about microphone input, although it is not possible to record without the use of a remote server like the Flash Media Server, nor is it currently possible to use computeSpectrum() to analyze the waveform, as demonstrated with MP3 source material. Instead, we can reflect something akin to the amplitude of the sound, which, in the parlance of the ActionScript 3.0 Microphone class, is called activityLevel.

Much of the code in this example will be familiar to you by now, so we'll jump right in to explain the microphone.fla source file. The first six lines of this script are important in that they initialize the microphone for use.

Line 1 creates an instance of the microphone using the getMicrophone() method of the static class Microphone. In order to work with the data of the microphone, you'll need to loop it back into Flash, in line 2. When doing so, it is best to use echo suppression, shown in line 3, to minimize feedback from your speakers during recording. Finally, lines 4 through 6 initialize the gain (amplitude of the recording), sample rate (11.050 kHz for basic voice input), and silence level. The latter is a convenient filter, if you will, to tell Flash what level of input, sustained for how many milliseconds, should be ignored as inactivity. This helps reduce the input of background noise.

1 var mic:Microphone = Microphone.getMicrophone(); 2 mic.setLoopBack(true); 3 mic.setUseEchoSuppression(true); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required