Microphone class

The Microphone class lets you capture audio from a microphone attached to the computer that is running Flash Player.

When used with Flash Media Server, you can transmit, play, and on Flash Media Interactive Server and Flash Media Development Server, optionally record the audio being captured. With these capabilities, you can develop a wide range of media applications. You can implement real-time collaboration applications using audio/video, such as Adobe® ConnectNow on Acrobat.com. Other examples are instant messaging with audio, applications to record presentations so that others can replay them later, and so on. Flash Player provides similar video capabilities; for more information, see the Camera class entry.

You can also use a Microphone object without a server—for example, to transmit sound from your microphone through the speakers on your local system.

To create or reference a Microphone object, use the Microphone.get() method.

Note: Flash Player displays a Privacy dialog box in which the user can choose whether to allow or deny access to the microphone. Make sure that your Stage size is at least 215 by 138 pixels; this is the minimum size that Flash Player requires to display the dialog box.

Availability

Flash Media Server (not required); Flash Player 6.

Method summary

Method

Description

Microphone.get()

Returns a reference to a microphone for capturing audio.

Microphone.setCodec()

Sets the codec used to compress audio.

Microphone.setEncodeQuality()

Sets the encoded speech quality when using the Speex codec.

Microphone.setFramesPerPacket()

Sets the number of Speex speech frames transmitted in a packet (message).

Microphone.setGain()

Specifies the amount by which the microphone should boost the signal before transmitting it.

Microphone.setRate()

Specifies the rate at which the microphone should capture sound, in kHz.

Microphone.setSilenceLevel()

Sets the minimum input level that should be considered sound and (optionally) the amount of silent time signifying that silence has actually begun.

Microphone.setUseEchoSuppression()

Specifies whether to use the echo suppression feature of the audio codec.

Property summary

Property (read-only)

Description

Microphone.activityLevel

The amount of sound the microphone is detecting.

Microphone.codec

The codec used to compress audio.

Microphone.encodeQuality

The encoded speech quality when using the Speex codec.

Microphone.framesPerPacket

Number of Speex speech frames transmitted in a packet (message).

Microphone.gain

The amount by which the microphone boosts the signal before transmitting it.

Microphone.index

A zero-based integer that specifies the index of the microphone, as reflected in the array returned by Microphone.names.

Microphone.muted

A Boolean value that specifies whether the user has allowed or denied access to the microphone.

Microphone.name

The name of the current sound capture device, as returned by the sound capture hardware.

Microphone.names

Class property: an array of strings reflecting the names of all available sound capture devices, including sound capture cards and microphones.

Microphone.rate

The sound capture rate, in kHz.

Microphone.silenceLevel

The amount of sound required to activate the microphone.

Microphone.silenceTimeout

The number of milliseconds between the time the microphone stops detecting sound and the time Microphone.onActivity()(false) is called.

Microphone.useEchoSuppression

A Boolean value that specifies whether echo suppression is being used.

Event handler summary

Event

Description

Microphone.onActivity()

Invoked when the microphone starts or stops detecting sound.

Microphone.onStatus()

Invoked when the user allows or denies access to the microphone.

Microphone constructor

Microphone.activityLevel

public activityLevel : Number [read-only]

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 neither MovieClip.attachAudio() nor NetStream.attachAudio() has been called, this property is set to ‑1.

Availability

Flash Media Server (not required); Flash Player 6.

Example

The following example displays the activity level of the current microphone in a ProgressBar instance called 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); 
};
Note: 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 DepthManager class from the component framework instead of the MovieClip.getNextHighestDepth() method.

Microphone.codec

public codec : String [read-only]

The codec used to compress audio. Possible values are "NELLYMOSER" (the default value) and "SPEEX". To set this value, use the setCodec() method.

Availability

Flash Media Server 3.5 (not required); Flash Player 10.

Microphone.encodeQuality

public encodeQuality: Number [read-only]

The encoded speech quality when using the Speex codec. Possible values are from 0 to 10. The default value is 6. Higher numbers represent higher quality but require more bandwidth, as shown in the following table. The bit rate values that are listed represent net bit rates and do not include packetization overhead.

Quality value

Required bit rate (kilobits per second)

0

3.95

1

5.75

2

7.75

3

9.8

4

12.8

5

16.8

6

20.6

7

23.8

8

27.8

9

34.2

10

42.2

Availability

Flash Media Server 3.5 (not required); Flash Player 10.

Microphone.framesPerPacket

public framesPerPacket : Number [read-only]

The number of Speex speech frames transmitted in a packet (message). Each frame is 20 ms long. The default value is two frames per packet.

Availability

Flash Media Server 3.5 (not required); Flash Player 10.

Microphone.gain

public gain : Number [read-only]

The amount by which the microphone boosts the signal before transmitting it. Valid values are 0 to 100. The default value is 50.

Availability

Flash Media Server (not required); Flash Player 6.

Example

The following example uses a ProgressBar instance called 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);
Note: 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 DepthManager class from the component framework instead of the MovieClip.getNextHighestDepth() method.

Microphone.get()

public static get([index:Number]) : Microphone
Note: The correct syntax is Microphone.get(). To assign the Microphone object to a variable, use syntax like var active_mic:Microphone = Microphone.get().

Returns a reference to a Microphone object for capturing audio. To begin capturing the audio, you must attach the Microphone object either to a MovieClip object (see MovieClip.attachAudio()) or to a NetStream object (see NetStream.attachAudio()). (The NetStream object is available only with Flash Media Server.)

Unlike objects that you create by 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, the user can specify the default microphone that Flash Player 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 NetStream.attachAudio() or MovieClip.attachAudio()—Flash Player displays a Privacy dialog box in which the user can choose whether to allow or deny access to the microphone. (Make sure that your Stage size is at least 215 by 138 pixels; this is the minimum size that Flash Player 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 and selecting Settings. When the Privacy dialog box opens, the user selects Remember.

You can’t use ActionScript to set the Allow or Deny value for a user, but you can display the Privacy dialog box 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 Microphones.names.length. To display the Flash Player Microphone Settings panel, in which the user can choose the microphone to be referenced by Microphone.get(), use System.showSettings(2).

Availability

Flash Media Server (not required); Flash Player 6.

Parameters

index
An optional zero-based integer that specifies which microphone to get, as determined from the array returned by Microphone.names. To get the default microphone (which is recommended for most applications), omit this parameter.

Returns

If index is not specified, this method returns a reference to the default microphone, or if it is not available, to the first available microphone. If no microphones are available or installed, the method returns null.

If index is specified, this method returns a reference to the requested microphone, or null if it is not available.

Example

The following example lets the user specify the default microphone and then captures audio and plays it back locally. To avoid feedback, you may want to test this code while wearing headphones.

this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth()); 
System.showSettings(2); 
var active_mic:Microphone = Microphone.get(); 
sound_mc.attachAudio(active_mic);
Note: 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 DepthManager class from the component framework instead of the MovieClip.getNextHighestDepth() method.

Microphone.index

public index : Number [read-only]

A zero-based integer that specifies the index of the microphone, as reflected in the array returned by Microphone.names.

Availability

Flash Media Server (not required); Flash Player 6.

Example

The following example displays the names of the sound capturing devices available on your computer system in a ComboBox instance called 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);
Note: 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 DepthManager class from the component framework instead of the MovieClip.getNextHighestDepth() method.

Microphone.muted

public muted : Boolean [read-only]

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().

Availability

Flash Media Server (not required); Flash Player 6.

Example

This example gets the default microphone and checks whether it is muted:

var active_mic:Microphone = Microphone.get(); 
trace(active_mic.muted);

Microphone.name

public name : String [read-only]

The name of the current sound capture device, as returned by the sound capture hardware.

Availability

Flash Media Server (not required); Flash Player 6.

Example

The following example displays information about the sound capture device or devices on your computer system, including an array of names and the default device:

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; 
}

Microphone.names

public static names : Array {read-only]
Note: The correct syntax is Microphone.names. To assign the return value to a variable, use syntax like var micNames_array:Array = Microphone.names. To determine the name of the current microphone, use active_mic.name, where active_mic is the variable to which you assigned the results of Microphone.get().

An array of strings reflecting the names of all available sound capture devices. This API gets the names of all available sound capture devices without displaying the Flash Player Privacy dialog box to the user. 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).

Accessing 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.

Availability

Flash Media Server (not required); Flash Player 6.

Example

The following code returns information on the array of audio devices:

var allMicNames_array:Array = Microphone.names; 
trace("Microphone.names located these device(s):"); 
for(i=0; i < allMicNames_array.length; i++){ 
    trace("[" + i + "]: " + allMicNames_array[i]); 
}

For example, the following information could be displayed:

Microphone.names located these device(s): 
[0]: Crystal SoundFusion(tm) 
[1]: USB Audio Device

See also

Array class entry in the ActionScript 2.0 Language Reference, Microphone.get(), Microphone.name

Microphone.onActivity()

public onActivity = function(active:Boolean) {}

Invoked when the microphone starts or stops detecting sound.

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().

Availability

Flash Media Server (not required); Flash Player 6.

Parameters

active
A Boolean value set to true when the microphone starts detecting sound, and to false when it stops.

Example

The following example displays true or false in the Output panel when the microphone starts or stops detecting sound:

var active_mic:Microphone = Microphone.get(); 
_root.attachAudio(active_mic); 
active_mic.onActivity = function(mode){ 
    trace("The microphone detects sound: " + mode); 
    // Mode outputs either true or false. 
}

Microphone.onStatus()

public onStatus = function(infoObject:Object) {}

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 in which the user can choose whether to allow or deny access.

  • If the user allows access, the Microphone.muted property is set to false, and this event handler is invoked with an information object whose code property is Microphone.Unmuted.

  • If the user denies access, the Microphone.muted property is set to true, and this event handler is invoked with an information object whose code property is Microphone.Muted.

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 for 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().

Availability

Flash Media Server (not required); Flash Player 6.

Parameters

infoObject
An object with code and level properties that provide information about the status of a Microphone object, as follows:

code property

level property

Meaning

Microphone.Muted

status

The user denied access to a microphone.

Microphone.Unmuted

status

The user allowed access to a microphone.

Example

The following example displays the Privacy dialog box, where the user can allow or deny access to the microphone. If the user chooses to deny access, “muted” is displayed in large red text. If microphone access is allowed, the user does not see this text.

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;
Note: 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 DepthManager class from the component framework instead of the MovieClip.getNextHighestDepth() method.

Microphone.rate

public rate : Number [read-only]

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().

Availability

Flash Media Server (not required); Flash Player 6.

Example

The following example saves the current rate to the variable original:

var active_mic:Microphone = Microphone.get(); 
var original:Number = active_mic.rate;

Microphone.setCodec()

public setCodec(codec:String) : Void

Sets the codec used to compress audio. Available codecs are Nellymoser (the default value) and Speex.

If you use the Nellymoser codec, you can set the sample rate using Microphone.setRate(). If you use the Speex codec, the sample rate is set to 16 kHz.

Speex includes voice activity detection (VAD) and automatically reduces bandwidth when no voice is detected. When using the Speex codec, Adobe recommends that you set the silence level to 0. To set the silence level, use the Microphone.setSilenceLevel() method.

Availability

Flash Media Server 3.5 (not required); Flash Player 10.

Parameters

codec
A string that specifies the codec to use. Possible values are "NELLYMOSER" (the default value) and "SPEEX".

Microphone.setEncodeQuality()

public setEncodeQuality(quality:Number) : Void

Sets the encoded speech quality when using the Speex codec.

Availability

Flash Media Server 3.5 (not required); Flash Player 10.

Parameters

quality
An integer that specifies the encoded speech quality. Possible values are from 0 to 10. The default value is 6. Higher numbers represent higher quality but require more bandwidth, as shown in the following table. The bit rate values that are listed represent net bit rates and do not include packetization overhead.

Quality value

Required bit rate (kilobits per second)

0

3.95

1

5.75

2

7.75

3

9.8

4

12.8

5

16.8

6

20.6

7

23.8

8

27.8

9

34.2

10

42.2

Microphone.setFramesPerPacket()

public setFramesPerPacket(frames:Number) : Void

Sets the 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. Fewer Speex frames increases bandwidth required but reduces delay.

Availability

Flash Media Server 3.5 (not required); Flash Player 10.

Parameters

frames
An integer that specifies the number of Speex frames per message.

Microphone.setGain()

public setGain(gain:Number) : Void

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 Player 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, and numbers above 50 specify higher than normal volume.

Availability

Flash Media Server (not required); Flash Player 6.

Parameters

gain
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 can change this value in the Flash Player Microphone Settings panel.

Example

The following example ensures that the microphone gain setting is less than or equal to 55.

var active_mic:Microphone = Microphone.get(); 
if (active_mic.gain > 55){ 
    active_mic.setGain(55); 
}

Microphone.setRate()

public setRate(kHz:Number) : Void

Sets the rate, in kHz, at which the microphone should capture sound when using the Nellymoser codec. When using the Speex codec, the sampling rate is set to 16 kHz.

Availability

Flash Media Server (not required); Flash Player 6.

Parameters

kHz
The rate at which the microphone should capture sound, in kHz, when using the Nellymoser codec. 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.

Example

The following example sets the microphone rate to the user’s preference (which you have assigned to the 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);

Microphone.setSilenceLevel()

public setSilenceLevel(silenceLevel:Number, [timeOut:Number]) : Void

Sets the minimum input level that should be considered sound and (optionally) the amount of silent time signifying that silence has actually begun.

  • To prevent the microphone from detecting sound at all, pass a value of 100 for silenceLevel; Microphone.onActivity() is never invoked.

  • To determine the amount of sound the microphone is currently detecting, use Microphone.activityLevel.

  • When using the Speex codec, pass a value of 0 for silenceLevel. Speex includes voice activity detection (VAD) and automatically reduces bandwidth when no voice is detected.

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 that 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.

Availability

Flash Media Server (not required); Flash Player 6.

Parameters

silenceLevel
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
An optional integer parameter that specifies how many milliseconds must elapse without activity before Flash Player considers sound to have stopped and invokes Microphone.onActivity(false). The default value is 2000 (2 seconds).

Example

The following example changes the silence level based on the user’s input in a NumericStepper instance called silenceLevel_nstep. The ProgressBar instance called silenceLevel_pb modifies its appearance depending on whether the audio stream is considered silent. If the audio stream is not silent, the progress bar 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)"; 
    } 
};
Note: 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 DepthManager class from the component framework instead of the MovieClip.getNextHighestDepth() method.

See also the example for Camera.setMotionLevel().

Microphone.setUseEchoSuppression()

public setUseEchoSuppression(suppress:Boolean) : Void

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 that 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.

Availability

Flash Media Server (not required); Flash Player 6.

Parameters

suppress
A Boolean value indicating whether echo suppression should be used (true) or not (false).

Example

The following example turns on echo suppression if the user selects a CheckBox instance called 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);

Microphone.silenceLevel

public silenceLevel : Number [read-only]

An integer that specifies the amount of sound required to activate the microphone and invoke Microphone.onActivity(true). The default value is 10.

Availability

Flash Media Server (not required); Flash Player 6.

Example

The following example changes the silence level based on the user’s input in a NumericStepper instance called silenceLevel_nstep. The ProgressBar instance called silenceLevel_pb modifies its appearance depending on whether the audio stream is considered silent. If the audio stream is not silent, the progress bar 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)"; 
    } 
};
Note: 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 DepthManager class from the component framework instead of the MovieClip.getNextHighestDepth() method.

Microphone.silenceTimeout

public 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. The default value is 2000 (2 seconds).

To set this value, use Microphone.setSilenceLevel().

Availability

Flash Media Server (not required); Flash Player 6.

Example

The following example enables the user to control the amount of time between when the microphone stops detecting sound and when Microphone.onActivity(false) is invoked. The user controls this value by 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. If the audio stream is not silent, the progress bar 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)"; 
    } 
};
Note: 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 DepthManager class from the component framework instead of the MovieClip.getNextHighestDepth() method.

Microphone.useEchoSuppression

public useEchoSuppression : Boolean [read-only]

A Boolean value that specifies whether echo suppression is being used. This property is true if echo suppression is enabled, and otherwise false. The default value is false unless the user has selected Reduce Echo in the Flash Player Microphone Settings panel.

Availability

Flash Media Server (not required); Flash Player 6.

Example

The following example turns on echo suppression if the user selects a CheckBox instance called 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);
Note: 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 DepthManager class from the component framework instead of the MovieClip.getNextHighestDepth() method.