Posted By

chrisaiv on 10/26/09


Tagged

sound as3


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

forze
test200
TrentSkunk
letmein_xxi


Flash: Microphone


 / Published in: ActionScript 3
 

Here's an example of how to use the Microphone API in Flash

  1. trace("Available sound input devices:");
  2.  
  3. //Detect which Microphone Devices are available
  4. var deviceArray:Array = Microphone.names;
  5. for (var i:int = 0; i < deviceArray.length; i++)
  6. {
  7. trace(" " + deviceArray[i]);
  8. }
  9.  
  10. //Create a new Microphone
  11. var mic:Microphone = Microphone.getMicrophone();
  12. //Default = 50
  13. mic.gain = 60;
  14. //22Kbs
  15. mic.rate = 22;
  16. //Set this to true if you're not using a Headset
  17. mic.setUseEchoSuppression(true);
  18. //Routes the Audio Captured back to the Local Speakers
  19. mic.setLoopBack(true);
  20. //Level of Noise Supression
  21. mic.setSilenceLevel(2, 1000);
  22.  
  23. mic.addEventListener( ActivityEvent.ACTIVITY, this.onMicActivity);
  24. mic.addEventListener( StatusEvent.STATUS, this.onMicStatus);
  25.  
  26. var micDetails:String = "Sound input device name: " + mic.name + '\n';
  27. micDetails += "Gain: " + mic.gain + '\n';
  28. micDetails += "Rate: " + mic.rate + " kHz" + '\n';
  29. micDetails += "Muted: " + mic.muted + '\n';
  30. micDetails += "Silence level: " + mic.silenceLevel + '\n';
  31. micDetails += "Silence timeout: " + mic.silenceTimeout + '\n';
  32. micDetails += "Echo suppression: " + mic.useEchoSuppression + '\n';
  33. micText1.text = micDetails;
  34.  
  35. function onMicActivity(evt:ActivityEvent):void
  36. {
  37. trace("activating=" + evt.activating + ", activityLevel=" + mic.activityLevel);
  38. meter_mc.mask_mc.scaleX = mic.activityLevel / 100;
  39. }
  40.  
  41. function onMicStatus(evt:StatusEvent):void
  42. {
  43. trace("status: level=" + evt.level + ", code=" + evt.code);
  44. }

Report this snippet  

You need to login to post a comment.