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(); |
| 6 Comments » | facebook:
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
Thank you very much! This is great!
I’d like to ask something: as the baby hears no sound, he doesn’ t close its eyes immediatly. How does it work?
Is that due to the microphone feedback or to the animation movieclip?
Thank you!
giuliano
Comment by giuliano — January 7, 2011 @ 4:21 am
There may be feed back that is preventing him from closing his eye immediately. The baby is a movieClip with ten frames, the frames are advanced by the activityLevel of the mic. On laptops you may get more feedback, as the mic picks up the sound from the speakers because they are so close. For Flash Player 10.1 there were a couple new properties added to the Microphone class, noiseSuppressionLevel and enableVAD, these allow for better feedback protection.
Comment by taterboy — January 10, 2011 @ 10:05 am
Thank you so much!
Comment by giuliano — January 12, 2011 @ 3:55 pm