A Microphone And A Baby - Flash AS3 Microphone Class – taterboy
May 21st, 2010 | Filed under: ActionScript 3, Audio, Flex, Tips
Here is a little demo from some recent playing with Flash’s Microphone class.

This is basically a microphone level meter that my son and I thought was pretty fun. Don’t wake the baby.
If you are using a laptop (were your microphone is close to your speakers) you will have to turn your volume down or use the mute button on the demo to prevent some nasty feedback.
Note: The feeback issue really is lowdown, but when Flash 10.1 comes out with its updated Microphone class, hopefully we will be able to fix it with actionScript.
The Code:
import flash.media.Microphone; import flash.system.Security; import flash.system.SecurityPanel; var mic:Microphone; var cryNum:Number = 0; var isMuted:Boolean; function init():void{ //setup the microphone mic = Microphone.getMicrophone(); //set the sample-rate to 44 khz mic.rate = 44; //adjust the gain - (0 - 100) - default 50; //mic.gain = 50; // send the audio from the mic to the speakers. this can cause terrible feedback. Other options are to connect the audio to a netStream. mic.setLoopBack(true); //set echo supression mic.setUseEchoSuppression(true); //pop open the security panel, but sense we are looping back to the speakers, the security box opens automatically //Security.showSettings(SecurityPanel.MICROPHONE); } // mute/unmute all sounds function muteSounds(val:Boolean):void{ isMuted = !isMuted; var trans:SoundTransform; if(isMuted){ trans = new SoundTransform(0); SoundMixer.soundTransform = trans; } else{ trans = new SoundTransform(1); SoundMixer.soundTransform = trans; } } function frameHandler(ev:Event):void{ /* the babyFace MovieClip is an animation consisting of 10 frames, I use the data from "mic.activityLevel (0 - 100) to move the animation to the correct frame. */ cryNum = Math.floor(mic.activityLevel/10); babyFace.gotoAndStop(cryNum + 1); } addEventListener(Event.ENTER_FRAME, frameHandler); // call init init(); stop(); |
|
RSS feed for comments on this post. TrackBack URL
[...] A Microphone Aחԁ A Baby – Flash AS3 Microphone Class | Taterboy.com: Graphics, Multi… [...]
Pingback by Audio Extender: Stream audio and microphone long distances over Cat5 cable — June 4, 2010 @ 1:41 pm
Thanks very much for your post. It has helped me quite a bit. :)
Comment by Daniel — June 21, 2010 @ 8:08 pm
Thanks a lot, great tutorial. Very informative and useful. God bless dude!
Comment by Andrew Oltlon — August 14, 2010 @ 5:19 pm