Using the Microphone in AS3


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // To also get the setting box here you can choose the Mic settings and choose a Mic, use :
  2. // Security.showSettings(SecurityPanel.MICROPHONE);
  3.  
  4. var deviceArray:Array = Microphone.names;
  5. trace("Available sound input devices:");
  6. for (var i:int = 0; i < deviceArray.length; i++) {
  7. trace(" " + deviceArray[i]);
  8. }
  9.  
  10. var mic:Microphone = Microphone.getMicrophone();
  11. mic.gain = 60;
  12. mic.rate = 11;
  13. mic.setUseEchoSuppression(true);
  14. mic.setLoopBack(true);
  15. mic.setSilenceLevel(5, 1000);
  16.  
  17. mic.addEventListener(ActivityEvent.ACTIVITY, this.onMicActivity);
  18. mic.addEventListener(StatusEvent.STATUS, this.onMicStatus);
  19.  
  20. var micDetails:String = "Sound input device name: " + mic.name + '\n';
  21. micDetails += "Gain: " + mic.gain + '\n';
  22. micDetails += "Rate: " + mic.rate + " kHz" + '\n';
  23. micDetails += "Muted: " + mic.muted + '\n';
  24. micDetails += "Silence level: " + mic.silenceLevel + '\n';
  25. micDetails += "Silence timeout: " + mic.silenceTimeout + '\n';
  26. micDetails += "Echo suppression: " + mic.useEchoSuppression + '\n';
  27.  
  28. function onMicActivity(evt:ActivityEvent):void {
  29. trace("activating=" + evt.activating + ", activityLevel=" + mic.activityLevel);
  30. }
  31.  
  32. function onMicStatus(evt:StatusEvent):void {
  33. trace("status: level=" + evt.level + ", code=" + evt.code);
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.