Package | Top Level |
Class | public class Microphone |
Inheritance | Microphone Object |
Player version: | Flash Player 6 |
The Microphone class is primarily for use with Flash Media Server but can be used in a limited fashion without the server, for example, to transmit sound from your microphone through the speakers on your local system.
Caution: Flash Player displays a Privacy dialog box that lets the user choose whether to allow or deny access to the microphone. Make sure your Stage size is at least 215 x 138 pixels; this is the minimum size Flash requires to display the dialog box.
Users and Administrative users may also disable microphone access on a per-site or global basis.
To create or reference a Microphone object, use the Microphone.get()
method.
Property | ||
---|---|---|
activityLevel : Number
[read-only]A numeric value that specifies the amount of sound the microphone is detecting.
|
||
codec : String
[read-only]The codec used to compress audio.
|
||
encodeQuality : Number
[read-only]The encoded speech quality when using Speex codex.
|
||
framesPerPacket : Number
[read-only]Number of Speex speech frames transmitted in a packet (message).
|
||
gain : Number
[read-only]The amount by which the microphone boosts the signal.
|
||
index : Number
[read-only]A zero-based integer that specifies the index of the microphone, as reflected in the array returned by
Microphone.names . |
||
muted : Boolean
[read-only]A Boolean value that specifies whether the user has denied access to the microphone (
true ) or allowed access (false ). |
||
name : String
[read-only]A string that specifies the name of the current sound capture device, as returned by the sound capture hardware.
|
||
names : Array
[static][read-only]Retrieves an array of strings reflecting the names of all available sound capture devices without displaying the Flash Player Privacy Settings panel.
|
||
rate : Number
[read-only]The rate at which the microphone is capturing sound, in kHz.
|
||
silenceLevel : Number
[read-only]An integer that specifies the amount of sound required to activate the microphone and invoke
Microphone.onActivity(true) . |
||
silenceTimeOut : Number
[read-only]A numeric value representing the number of milliseconds between the time the microphone stops detecting sound and the time
Microphone.onActivity(false) is invoked. |
||
useEchoSuppression : Boolean
[read-only]Property (read-only); a Boolean value of
true if echo suppression is enabled, false otherwise. |
Properties inherited from class Object | |
---|---|
__proto__, __resolve, constructor, prototype |
Method | ||
---|---|---|
[static]Returns a reference to a Microphone object for capturing audio.
|
||
Sets the codec used to compress audio.
|
||
setEncodeQuality(quality:Number):Void
Sets the encoded speech quality for using the Speex codec.
|
||
setFramesPerPacket(frames:Number):Void
Sets the number of Speex speech frames transmitted in a packet (message).
|
||
Sets the microphone gain--that is, the amount by which the microphone should multiply the signal before transmitting it.
|
||
Sets the rate, in kHz, at which the microphone should capture sound.
|
||
Sets the minimum input level that should be considered sound and (optionally) the amount of silent time signifying that silence has actually begun.
|
||
setUseEchoSuppression(useEchoSuppression:Boolean):Void
Specifies whether to use the echo suppression feature of the audio codec.
|
Methods inherited from class Object | |
---|---|
addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch |
Event | Summary | Defined by | ||
---|---|---|---|---|
onActivity = function(active:Boolean) {}
| Invoked when the microphone starts or stops detecting sound. | Microphone | ||
Invoked when the user allows or denies access to the microphone. | Microphone |
activityLevel | property |
activityLevel:Number
[read-only]
Player version: | Flash Player 6 |
A numeric value that specifies the amount of sound the microphone is detecting. Values range from 0 (no sound is being detected) to 100 (very loud sound is being detected). The value of this property can help you determine a good value to pass to the Microphone.setSilenceLevel()
method.
If the microphone is available but is not yet being used because Microphone.get()
has not been called, this property is set to -1.
public function get activityLevel():Number
See also
activityLevel_pb
. var activityLevel_pb:mx.controls.ProgressBar; activityLevel_pb.mode = "manual"; activityLevel_pb.label = "Activity Level: %3%%"; activityLevel_pb.setStyle("themeColor", "0xFF0000"); this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); this.onEnterFrame = function() { activityLevel_pb.setProgress(active_mic.activityLevel, 100); }; active_mic.onActivity = function(active:Boolean) { if (active) { var haloTheme_str:String = "haloGreen"; } else { var haloTheme_str:String = "0xFF0000"; } activityLevel_pb.setStyle("themeColor", haloTheme_str); };
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
codec | property |
codec:String
[read-only]
Language version: | ActionScript 2.0 |
Player version: | Flash Player 10 |
The codec used to compress audio. Possible values are "NELLYMOSER" (the default value) and "SPEEX".
To set this value, use the setCodec()
method.
public function get codec():String
See also
encodeQuality | property |
encodeQuality:Number
[read-only]
Language version: | ActionScript 2.0 |
Player version: | Flash Player 10 |
The encoded speech quality when using Speex codex.
Implementation public function get encodeQuality():Number
See also
framesPerPacket | property |
framesPerPacket:Number
[read-only]
Language version: | ActionScript 2.0 |
Player version: | Flash Player 10 |
Number of Speex speech frames transmitted in a packet (message). Each frame is 20 ms long. The default value is two frames per packet. The more Speex frames in a message, the lower the bandwidth required but the longer the delay in sending the message.
Implementation public function get framesPerPacket():Number
See also
gain | property |
gain:Number
[read-only]
Player version: | Flash Player 6 |
The amount by which the microphone boosts the signal. Valid values are 0 to 100. The default value is 50.
Implementation public function get gain():Number
See also
gain_pb
to display and a NumericStepper instance called gain_nstep
to set the microphone's gain value. this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); gain_pb.label = "Gain: %3"; gain_pb.mode = "manual"; gain_pb.setProgress(active_mic.gain, 100); gain_nstep.value = active_mic.gain; function changeGain() { active_mic.setGain(gain_nstep.value); gain_pb.setProgress(active_mic.gain, 100); } gain_nstep.addEventListener("change", changeGain);
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
index | property |
index:Number
[read-only]
Player version: | Flash Player 6 |
A zero-based integer that specifies the index of the microphone, as reflected in the array returned by Microphone.names
.
public function get index():Number
See also
mic_cb
. An instance of the Label component, called mic_lbl
, displays the index microphone. You can use the ComboBox to switch between the devices. var mic_lbl:mx.controls.Label; var mic_cb:mx.controls.ComboBox; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); mic_lbl.text = "["+active_mic.index+"] "+active_mic.name; mic_cb.dataProvider = Microphone.names; mic_cb.selectedIndex = active_mic.index; var cbListener:Object = new Object(); cbListener.change = function(evt:Object) { active_mic = Microphone.get(evt.target.selectedIndex); sound_mc.attachAudio(active_mic); mic_lbl.text = "["+active_mic.index+"] "+active_mic.name; }; mic_cb.addEventListener("change", cbListener);
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
muted | property |
muted:Boolean
[read-only]
Player version: | Flash Player 6 |
A Boolean value that specifies whether the user has denied access to the microphone (true
) or allowed access (false
). When this value changes, Microphone.onStatus
is invoked. For more information, see Microphone.get()
.
public function get muted():Boolean
See also
var active_mic:Microphone = Microphone.get(); trace(active_mic.muted);
name | property |
name:String
[read-only]
Player version: | Flash Player 6 |
A string that specifies the name of the current sound capture device, as returned by the sound capture hardware.
Implementation public function get name():String
See also
var status_ta:mx.controls.TextArea; status_ta.html = false; status_ta.setStyle("fontSize", 9); var microphone_array:Array = Microphone.names; var active_mic:Microphone = Microphone.get(); status_ta.text = "The default device is: "+active_mic.name+newline+newline; status_ta.text += "You have "+microphone_array.length+" device(s) installed."+newline+newline; for (var i = 0; i<microphone_array.length; i++) { status_ta.text += "["+i+"] "+microphone_array[i]+newline; }
names | property |
names:Array
[read-only]
Player version: | Flash Player 6 — Note: The correct syntax is Microphone.names. To assign the return value to a variable, use syntax like mic_array=Microphone.names. To determine the name of the current microphone, use active_mic.name. |
Retrieves an array of strings reflecting the names of all available sound capture devices without displaying the Flash Player Privacy Settings panel. This array behaves the same as any other ActionScript array, implicitly providing the zero-based index of each sound capture device and the number of sound capture devices on the system (by means of Microphone.names.length
). For more information, see the Microphone.names Array class entry.
Calling Microphone.names
requires an extensive examination of the hardware, and it may take several seconds to build the array. In most cases, you can just use the default microphone.
public static function get names():Array
See also
var status_ta:mx.controls.TextArea; status_ta.html = false; status_ta.setStyle("fontSize", 9); var microphone_array:Array = Microphone.names; var active_mic:Microphone = Microphone.get(); status_ta.text = "The default device is: "+active_mic.name+newline+newline; status_ta.text += "You have "+microphone_array.length+" device(s) installed."+newline+newline; for (var i = 0; i<microphone_array.length; i++) { status_ta.text += "["+i+"] "+microphone_array[i]+newline; }
For example, the following information could be displayed:
The default device is: Logitech USB Headset You have 2 device(s) installed. [0] Logitech USB Headset [1] YAMAHA AC-XG WDM Audio
rate | property |
rate:Number
[read-only]
Player version: | Flash Player 6 |
The rate at which the microphone is capturing sound, in kHz. The default value is 8 kHz if your sound capture device supports this value. Otherwise, the default value is the next available capture level above 8 kHz that your sound capture device supports, usually 11 kHz.
To set this value, use Microphone.setRate()
.
public function get rate():Number
See also
rate_cb
, to change the rate at which your microphone captures sound. The current rate displays in a Label instance called rate_lbl
. this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); var rate_array:Array = new Array(5, 8, 11, 22, 44); rate_cb.dataProvider = rate_array; rate_cb.labelFunction = function(item:Object) { return (item+" kHz"); }; for (var i = 0; i<rate_array.length; i++) { if (rate_cb.getItemAt(i) == active_mic.rate) { rate_cb.selectedIndex = i; break; } } function changeRate() { active_mic.setRate(rate_cb.selectedItem); rate_lbl.text = "Current rate: "+active_mic.rate+" kHz"; } rate_cb.addEventListener("change", changeRate); rate_lbl.text = "Current rate: "+active_mic.rate+" kHz";
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
silenceLevel | property |
silenceLevel:Number
[read-only]
Player version: | Flash Player 6 |
An integer that specifies the amount of sound required to activate the microphone and invoke Microphone.onActivity(true)
. The default value is 10.
public function get silenceLevel():Number
See also
silenceLevel_nstep
. The ProgressBar instance called silenceLevel_pb
modifies its appearance depending on whether the audio stream is considered silent. Otherwise, it displays the activity level of the audio stream. var silenceLevel_pb:mx.controls.ProgressBar; var silenceLevel_nstep:mx.controls.NumericStepper; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); silenceLevel_pb.label = "Activity level: %3"; silenceLevel_pb.mode = "manual"; silenceLevel_nstep.minimum = 0; silenceLevel_nstep.maximum = 100; silenceLevel_nstep.value = active_mic.silenceLevel; var nstepListener:Object = new Object(); nstepListener.change = function(evt:Object) { active_mic.setSilenceLevel(evt.target.value, active_mic.silenceTimeOut); }; silenceLevel_nstep.addEventListener("change", nstepListener); this.onEnterFrame = function() { silenceLevel_pb.setProgress(active_mic.activityLevel, 100); }; active_mic.onActivity = function(active:Boolean) { if (active) { silenceLevel_pb.indeterminate = false; silenceLevel_pb.setStyle("themeColor", "haloGreen"); silenceLevel_pb.label = "Activity level: %3"; } else { silenceLevel_pb.indeterminate = true; silenceLevel_pb.setStyle("themeColor", "0xFF0000"); silenceLevel_pb.label = "Activity level: (inactive)"; } };
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
silenceTimeOut | property |
silenceTimeOut:Number
[read-only]
Player version: | Flash Player 6 |
A numeric value representing the number of milliseconds between the time the microphone stops detecting sound and the time Microphone.onActivity(false)
is invoked. The default value is 2000 (2 seconds).
To set this value, use Microphone.setSilenceLevel()
.
public function get silenceTimeOut():Number
See also
Microphone.onActivity(false)
is invoked. The user controls this value using a NumericStepper instance called silenceTimeOut_nstep. The ProgressBar instance called silenceLevel_pb
modifies its appearance depending on whether the audio stream is considered silent. Otherwise, it displays the activity level of the audio stream. var silenceLevel_pb:mx.controls.ProgressBar; var silenceTimeOut_nstep:mx.controls.NumericStepper; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); silenceLevel_pb.label = "Activity level: %3"; silenceLevel_pb.mode = "manual"; silenceTimeOut_nstep.minimum = 0; silenceTimeOut_nstep.maximum = 10; silenceTimeOut_nstep.value = active_mic.silenceTimeOut/1000; var nstepListener:Object = new Object(); nstepListener.change = function(evt:Object) { active_mic.setSilenceLevel(active_mic.silenceLevel, evt.target.value 1000); }; silenceTimeOut_nstep.addEventListener("change", nstepListener); this.onEnterFrame = function() { silenceLevel_pb.setProgress(active_mic.activityLevel, 100); }; active_mic.onActivity = function(active:Boolean) { if (active) { silenceLevel_pb.indeterminate = false; silenceLevel_pb.setStyle("themeColor", "haloGreen"); silenceLevel_pb.label = "Activity level: %3"; } else { silenceLevel_pb.indeterminate = true; silenceLevel_pb.setStyle("themeColor", "0xFF0000"); silenceLevel_pb.label = "Activity level: (inactive)"; } };
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
useEchoSuppression | property |
useEchoSuppression:Boolean
[read-only]
Player version: | Flash Player 6 |
Property (read-only); a Boolean value of true
if echo suppression is enabled, false
otherwise. The default value is false
unless the user has selected Reduce Echo in the Flash Player Microphone Settings panel.
public function get useEchoSuppression():Boolean
See also
useEchoSuppression_ch
. The ProgressBar instance called activityLevel_pb
displays the current activity level of the audio stream. var useEchoSuppression_ch:mx.controls.CheckBox; var activityLevel_pb:mx.controls.ProgressBar; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); activityLevel_pb.mode = "manual"; activityLevel_pb.label = "Activity Level: %3"; useEchoSuppression_ch.selected = active_mic.useEchoSuppression; this.onEnterFrame = function() { activityLevel_pb.setProgress(active_mic.activityLevel, 100); }; var chListener:Object = new Object(); chListener.click = function(evt:Object) { active_mic.setUseEchoSuppression(evt.target.selected); }; useEchoSuppression_ch.addEventListener("click", chListener);
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
get | () | method |
public static function get([index:Number]):Microphone
Player version: | Flash Player 6 — Note: The correct syntax is Microphone.get(). To assign the Microphone object to a variable, use syntax like active_mic = Microphone.get(). |
Returns a reference to a Microphone object for capturing audio. To actually begin capturing the audio, you must attach the Microphone object to a MovieClip object (see MovieClip.attachAudio()
).
Unlike objects that you create using the new
constructor, multiple calls to Microphone.get()
reference the same microphone. Thus, if your script contains the lines mic1 = Microphone.get()
and mic2 = Microphone.get()
, both mic1
and mic2
reference the same (default) microphone.
In general, you shouldn't pass a value for index
; simply use the Microphone.get()
method to return a reference to the default microphone. By means of the Microphone settings panel (discussed later in this section), the user can specify the default microphone Flash should use. If you pass a value for index
, you might be trying to reference a microphone other than the one the user prefers. You might use index
in rare cases--for example, if your application is capturing audio from two microphones at the same time.
When a SWF file tries to access the microphone returned by the Microphone.get()
method--for example, when you issue MovieClip.attachAudio()
--Flash Player displays a Privacy dialog box that lets the user choose whether to allow or deny access to the microphone. (Make sure your Stage size is at least 215 x 138 pixels; this is the minimum size Flash requires to display the dialog box.)
When the user responds to this dialog box, the Microphone.onStatus
event handler returns an information object that indicates the user's response. To determine whether the user has denied or allowed access to the camera without processing this event handler, use Microphone.muted
.
The user can also specify permanent privacy settings for a particular domain by right-clicking (Windows) or Control-clicking (Macintosh) while a SWF file is playing, choosing Settings, opening the Privacy panel, and selecting Remember.
You can't use ActionScript to set the Allow or Deny value for a user, but you can display the Privacy panel for the user by using System.showSettings(0)
. If the user selects Remember, Flash Player no longer displays the Privacy dialog box for SWF files from this domain.
If Microphone.get()
returns null
, either the microphone is in use by another application, or there are no microphones installed on the system. To determine whether any microphones are installed, use Microphone.names.length
. To display the Flash Player Microphone Settings panel, which lets the user choose the microphone to be referenced by Microphone.get()
, use System.showSettings(2)
.
index:Number [optional] — A zero-based integer that specifies which microphone to get, as determined from the array that Microphone.names contains. To get the default microphone (which is recommended for most applications), omit this parameter. |
Microphone —
|
See also
this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); System.showSettings(2); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic);
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
setCodec | () | method |
public function setCodec(codec:String):Void
Language version: | ActionScript 2.0 |
Player version: | Flash Player 10 |
Sets the codec used to compress audio. Available codecs are Nellymoser (the default value) and Speex.
Speex includes voice activity detection (VAD) and automatically reduces bandwidth when no voice is detected. When you use the Speex codec, Adobe recommends that you set the silence level to 0. To set the silence level, use the Microphone.setSilenceLevel()
method.
codec:String — A string that specifies the codec. Valid values are "SPEEX" and "NELLYMOSER". |
See also
setEncodeQuality | () | method |
public function setEncodeQuality(quality:Number):Void
Language version: | ActionScript 2.0 |
Player version: | Flash Player 10 |
Sets the encoded speech quality for using the Speex codec. See the Flash Media Server documentation for more details.
Parametersquality:Number — A number between 0 and 10 that specifies quality. |
See also
setFramesPerPacket | () | method |
public function setFramesPerPacket(frames:Number):Void
Language version: | ActionScript 2.0 |
Player version: | Flash Player 10 |
Sets the number of Speex speech frames transmitted in a packet (message).
Parametersframes:Number — The number of Speex frames per message. |
See also
setGain | () | method |
public function setGain(gain:Number):Void
Player version: | Flash Player 6 |
Sets the microphone gain--that is, the amount by which the microphone should multiply the signal before transmitting it. A value of 0 tells Flash to multiply by 0; that is, the microphone transmits no sound.
You can think of this setting like a volume knob on a stereo: 0 is no volume and 50 is normal volume; numbers below 50 specify lower than normal volume, while numbers above 50 specify higher than normal volume.
Parametersgain:Number — An integer that specifies the amount by which the microphone should boost the signal. Valid values are 0 to 100. The default value is 50; however, the user may change this value in the Flash Player Microphone Settings panel. |
See also
gain_pb
to display and a NumericStepper instance called gain_nstep
to set the microphone's gain value. this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); gain_pb.label = "Gain: %3"; gain_pb.mode = "manual"; gain_pb.setProgress(active_mic.gain, 100); gain_nstep.value = active_mic.gain; function changeGain() { active_mic.setGain(gain_nstep.value); gain_pb.setProgress(active_mic.gain, 100); } gain_nstep.addEventListener("change", changeGain);
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
setRate | () | method |
public function setRate(rate:Number):Void
Player version: | Flash Player 6 |
Sets the rate, in kHz, at which the microphone should capture sound.
Parametersrate:Number — The rate at which the microphone should capture sound, in kHz. Acceptable values are 5, 8, 11, 22, and 44. The default value is 8 kHz if your sound capture device supports this value. Otherwise, the default value is the next available capture level above 8 kHz that your sound capture device supports, usually 11 kHz. |
See also
userRate
variable) if it is one of the following values: 5, 8, 11, 22, or 44. If it is not, the value is rounded to the nearest acceptable value that the sound capture device supports. active_mic.setRate(userRate);
The following example lets you use a ComboBox instance, called rate_cb
, to change the rate at which your microphone captures sound. The current rate displays in a Label instance called rate_lbl
.
this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); var rate_array:Array = new Array(5, 8, 11, 22, 44); rate_cb.dataProvider = rate_array; rate_cb.labelFunction = function(item:Object) { return (item+" kHz"); }; for (var i = 0; i<rate_array.length; i++) { if (rate_cb.getItemAt(i) == active_mic.rate) { rate_cb.selectedIndex = i; break; } } function changeRate() { active_mic.setRate(rate_cb.selectedItem); rate_lbl.text = "Current rate: "+active_mic.rate+" kHz"; } rate_cb.addEventListener("change", changeRate); rate_lbl.text = "Current rate: "+active_mic.rate+" kHz";
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
setSilenceLevel | () | method |
public function setSilenceLevel(silenceLevel:Number, [timeOut:Number]):Void
Player version: | Flash Player 6 |
Sets the minimum input level that should be considered sound and (optionally) the amount of silent time signifying that silence has actually begun.
level
; Microphone.onActivity
is never invoked. Microphone.activityLevel
. Activity detection is the ability to detect when audio levels suggest that a person is talking. When someone is not talking, bandwidth can be saved because there is no need to send the associated audio stream. This information can also be used for visual feedback so that users know they (or others) are silent.
Silence values correspond directly to activity values. Complete silence is an activity value of 0. Constant loud noise (as loud as can be registered based on the current gain setting) is an activity value of 100. After gain is appropriately adjusted, your activity value is less than your silence value when you're not talking; when you are talking, the activity value exceeds your silence value.
This method is similar in purpose to Camera.setMotionLevel()
; both methods are used to specify when the onActivity
event handler should be invoked. However, these methods have a significantly different impact on publishing streams:
Camera.setMotionLevel()
is designed to detect motion and does not affect bandwidth usage. Even if a video stream does not detect motion, video is still sent.Microphone.setSilenceLevel()
is designed to optimize bandwidth. When an audio stream is considered silent, no audio data is sent. Instead, a single message is sent, indicating that silence has started. silenceLevel:Number — An integer that specifies the amount of sound required to activate the microphone and invoke Microphone.onActivity(true) . Acceptable values range from 0 to 100. The default value is 10. |
|
timeOut:Number [optional] — An integer that specifies how many milliseconds must elapse without activity before Flash considers sound to have stopped and invokes Microphone.onActivity(false) . The default value is 2000 (2 seconds). |
See also
silenceLevel_nstep
. The ProgressBar instance called silenceLevel_pb
modifies its appearance depending on whether the audio stream is considered silent. Otherwise, it displays the activity level of the audio stream. var silenceLevel_pb:mx.controls.ProgressBar; var silenceLevel_nstep:mx.controls.NumericStepper; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); silenceLevel_pb.label = "Activity level: %3"; silenceLevel_pb.mode = "manual"; silenceLevel_nstep.minimum = 0; silenceLevel_nstep.maximum = 100; silenceLevel_nstep.value = active_mic.silenceLevel; var nstepListener:Object = new Object(); nstepListener.change = function(evt:Object) { active_mic.setSilenceLevel(evt.target.value, active_mic.silenceTimeOut); }; silenceLevel_nstep.addEventListener("change", nstepListener); this.onEnterFrame = function() { silenceLevel_pb.setProgress(active_mic.activityLevel, 100); }; active_mic.onActivity = function(active:Boolean) { if (active) { silenceLevel_pb.indeterminate = false; silenceLevel_pb.setStyle("themeColor", "haloGreen"); silenceLevel_pb.label = "Activity level: %3"; } else { silenceLevel_pb.indeterminate = true; silenceLevel_pb.setStyle("themeColor", "0xFF0000"); silenceLevel_pb.label = "Activity level: (inactive)"; } };
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
setUseEchoSuppression | () | method |
public function setUseEchoSuppression(useEchoSuppression:Boolean):Void
Player version: | Flash Player 6 |
Specifies whether to use the echo suppression feature of the audio codec. The default value is false
unless the user has selected Reduce Echo in the Flash Player Microphone Settings panel.
Echo suppression is an effort to reduce the effects of audio feedback, which is caused when sound going out the speaker is picked up by the microphone on the same computer. (This is different from echo cancellation, which completely removes the feedback.)
Generally, echo suppression is advisable when the sound being captured is played through speakers--instead of a headset--on the same computer. If your SWF file allows users to specify the sound output device, you may want to call Microphone.setUseEchoSuppression(true)
if they indicate they are using speakers and will be using the microphone as well.
Users can also adjust these settings in the Flash Player Microphone Settings panel.
ParametersuseEchoSuppression:Boolean — A Boolean value indicating whether echo suppression should be used (true ) or not(false ). |
See also
useEchoSuppression_ch
. The ProgressBar instance called activityLevel_pb
displays the current activity level of the audio stream. var useEchoSuppression_ch:mx.controls.CheckBox; var activityLevel_pb:mx.controls.ProgressBar; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); activityLevel_pb.mode = "manual"; activityLevel_pb.label = "Activity Level: %3"; useEchoSuppression_ch.selected = active_mic.useEchoSuppression; this.onEnterFrame = function() { activityLevel_pb.setProgress(active_mic.activityLevel, 100); }; var chListener:Object = new Object(); chListener.click = function(evt:Object) { active_mic.setUseEchoSuppression(evt.target.selected); }; useEchoSuppression_ch.addEventListener("click", chListener);
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
onActivity | event handler |
public onActivity = function(active:Boolean) {}
Player version: | Flash Player 6 |
Invoked when the microphone starts or stops detecting sound. If you want to respond to this event handler, you must create a function to process its activity value.
To specify the amount of sound required to invoke Microphone.onActivity(true)
, and the amount of time that must elapse without sound before Microphone.onActivity(false)
is invoked, use Microphone.setSilenceLevel()
.
active:Boolean — A Boolean value set to true when the microphone starts detecting sound, and false when it stops. |
activityLevel_pb
. When the microphone detects sound, it invokes the onActivity
function, which modifies the ProgressBar instance. var activityLevel_pb:mx.controls.ProgressBar; activityLevel_pb.mode = "manual"; activityLevel_pb.label = "Activity Level: %3%%"; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); active_mic.onActivity = function(active:Boolean) { if (active) { activityLevel_pb.indeterminate = false; activityLevel_pb.label = "Activity Level: %3%%"; } else { activityLevel_pb.indeterminate = true; activityLevel_pb.label = "Activity Level: (inactive)"; } }; this.onEnterFrame = function() { activityLevel_pb.setProgress(active_mic.activityLevel, 100); };
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
See also
onStatus | event handler |
public onStatus = function(infoObject:Object) {}
Player version: | Flash Player 6 |
Invoked when the user allows or denies access to the microphone. If you want to respond to this event handler, you must create a function to process the information object generated by the microphone.
When a SWF file tries to access the microphone, Flash Player displays a Privacy dialog box that lets the user choose whether to allow or deny access.
To determine whether the user has denied or allowed access to the microphone without processing this event handler, use Microphone.muted
.
Note: If the user chooses to permanently allow or deny access to all SWF files from a specified domain, this method is not invoked for SWF files from that domain unless the user later changes the privacy setting.
For more information, see Microphone.get()
.
infoObject:Object — A parameter defined according to the status message. |
this.createTextField("muted_txt", this.getNextHighestDepth(), 10, 10, 100, 22); muted_txt.autoSize = true; muted_txt.html = true; muted_txt.selectable = false; muted_txt.htmlText = "<a href=\"asfunction:System.showSettings\"><u>Click Here</u></a> to Allow/Deny access."; this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); var active_mic:Microphone = Microphone.get(); sound_mc.attachAudio(active_mic); active_mic.onStatus = function(infoObj:Object) { status_txt._visible = active_mic.muted; muted_txt.htmlText = "Status: <a href=\"asfunction:System.showSettings\"><u>"+infoObj.code+"</u></a>"; }; this.createTextField("status_txt", this.getNextHighestDepth(), 0, 0, 100, 22); status_txt.html = true; status_txt.autoSize = true; status_txt.htmlText = "<font size='72' color='#FF0000'>muted</font>"; status_txt._x = (Stage.width-status_txt._width)/2; status_txt._y = (Stage.height-status_txt._height)/2; status_txt._visible = active_mic.muted;
The MovieClip.getNextHighestDepth()
method used in this example requires Flash Player 7 or later. If your SWF file includes a version 2 component, use the version 2 components' DepthManager class instead of the MovieClip.getNextHighestDepth()
method.
See also