/ Published in: ActionScript 3

Here's an example of how to use the Microphone API in Flash
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
trace("Available sound input devices:"); //Detect which Microphone Devices are available var deviceArray:Array = Microphone.names; for (var i:int = 0; i < deviceArray.length; i++) { trace(" " + deviceArray[i]); } //Create a new Microphone var mic:Microphone = Microphone.getMicrophone(); //Default = 50 mic.gain = 60; //22Kbs mic.rate = 22; //Set this to true if you're not using a Headset mic.setUseEchoSuppression(true); //Routes the Audio Captured back to the Local Speakers mic.setLoopBack(true); //Level of Noise Supression mic.setSilenceLevel(2, 1000); mic.addEventListener( ActivityEvent.ACTIVITY, this.onMicActivity); mic.addEventListener( StatusEvent.STATUS, this.onMicStatus); var micDetails:String = "Sound input device name: " + mic.name + '\n'; micDetails += "Gain: " + mic.gain + '\n'; micDetails += "Rate: " + mic.rate + " kHz" + '\n'; micDetails += "Muted: " + mic.muted + '\n'; micDetails += "Silence level: " + mic.silenceLevel + '\n'; micDetails += "Silence timeout: " + mic.silenceTimeout + '\n'; micDetails += "Echo suppression: " + mic.useEchoSuppression + '\n'; micText1.text = micDetails; function onMicActivity(evt:ActivityEvent):void { trace("activating=" + evt.activating + ", activityLevel=" + mic.activityLevel); meter_mc.mask_mc.scaleX = mic.activityLevel / 100; } function onMicStatus(evt:StatusEvent):void { trace("status: level=" + evt.level + ", code=" + evt.code); }
Comments
