Microphone


Object   |   +-Microphone public class Microphone extends Object

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

The Microphone class is primarily for use with Flash Communication 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.

Availability: ActionScript 1.0; Flash Player 6

Property summary

Modifiers

Property

Description

 

activityLevel:Number [read-only]

A numeric value that specifies the amount of sound the microphone is detecting.

 

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.

static

names:Array [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

constructor (Object.constructor property), __proto__ (Object.__proto__ property), prototype (Object.prototype property), __resolve (Object.__resolve property)


Event summary

Event

Description

onActivity = function(active:Boolean) {}

Invoked when the microphone starts or stops detecting sound.

onStatus = function(infoObject:Object) {}

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


Method summary

Modifiers

Signature

Description

static

get([index:Number]) : Microphone

Returns a reference to a Microphone object for capturing audio.

 

setGain(gain:Number) : Void

Sets the microphone gain--that is, the amount by which the microphone should multiply the signal before transmitting it.

 

setRate(rate:Number) : Void

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

 

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.

 

setUseEchoSuppression(useEchoSuppression:Boolean) : Void

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


Methods inherited from class Object

addProperty (Object.addProperty method), hasOwnProperty (Object.hasOwnProperty method), isPropertyEnumerable (Object.isPropertyEnumerable method), isPrototypeOf (Object.isPrototypeOf method), registerClass (Object.registerClass method), toString (Object.toString method), unwatch (Object.unwatch method), valueOf (Object.valueOf method), watch (Object.watch method)


activityLevel (Microphone.activityLevel property)

public activityLevel : Number [read-only]

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.

Availability: ActionScript 1.0; 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); };

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

get (Microphone.get method), setSilenceLevel (Microphone.setSilenceLevel method), setGain (Microphone.setGain method)

gain (Microphone.gain property)

public gain : Number [read-only]

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

Availability: ActionScript 1.0; 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);

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

setGain (Microphone.setGain method)

get (Microphone.get method)

public static get([index:Number]) : Microphone

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

Availability: ActionScript 1.0; 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().

Parameters

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.

Returns

Microphone-

  • 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);

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

get (Microphone.get method), index (Microphone.index property), muted (Microphone.muted property), names (Microphone.names property), onStatus (Microphone.onStatus handler), attachAudio (MovieClip.attachAudio method), showSettings (System.showSettings method)

index (Microphone.index property)

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: ActionScript 1.0; 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);

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

get (Microphone.get method), names (Microphone.names property)

muted (Microphone.muted property)

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: ActionScript 1.0; 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);

See also

get (Microphone.get method), onStatus (Microphone.onStatus handler)

name (Microphone.name property)

public name : String [read-only]

A string that specifies the name of the current sound capture device, as returned by the sound capture hardware.

Availability: ActionScript 1.0; Flash Player 6

Example

The following example displays information about the sound capturing device(s) 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; }

See also

get (Microphone.get method), names (Microphone.names property)

names (Microphone.names property)

public static names : Array [read-only]

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.

Availability: ActionScript 1.0; 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.

Example

The following example displays information about the sound capturing device(s) 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; }

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

See also

name (Microphone.name property), get (Microphone.get method)

onActivity (Microphone.onActivity handler)

onActivity = function(active:Boolean) {}

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

Availability: ActionScript 1.0; Flash Player 6

Parameters

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

Example

The following example displays the amount of activity level in a ProgressBar instance called 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

setSilenceLevel (Microphone.setSilenceLevel method)

onStatus (Microphone.onStatus handler)

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 that lets the user 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" and whose level property is "Status".

  • 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" and whose level property is "Status".

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

Availability: ActionScript 1.0; Flash Player 6

Parameters

infoObject :Object - A parameter defined according to the status message.

Example

The following example launches the Privacy dialog box that lets the user choose whether to allow or deny access to the microphone when they click a hyperlink. 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;

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

get (Microphone.get method), muted (Microphone.muted property), showSettings (System.showSettings method), onStatus (System.onStatus handler)

rate (Microphone.rate property)

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: ActionScript 1.0; Flash Player 6

Example

The following code 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.

See also

setRate (Microphone.setRate method)

setGain (Microphone.setGain method)

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

Availability: ActionScript 1.0; Flash Player 6

Parameters

gain :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.

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

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

gain (Microphone.gain property), setUseEchoSuppression (Microphone.setUseEchoSuppression method)

setRate (Microphone.setRate method)

public setRate(rate:Number) : Void

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

Availability: ActionScript 1.0; Flash Player 6

Parameters

rate :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.

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

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.

See also

rate (Microphone.rate property)

setSilenceLevel (Microphone.setSilenceLevel method)

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 level; Microphone.onActivity is never invoked.

  • To determine the amount of sound the microphone is currently detecting, use 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.

Availability: ActionScript 1.0; Flash Player 6

Parameters

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

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

See also

setMotionLevel (Camera.setMotionLevel method), activityLevel (Microphone.activityLevel property), onActivity (Microphone.onActivity handler), setGain (Microphone.setGain method), silenceLevel (Microphone.silenceLevel property), silenceTimeOut (Microphone.silenceTimeOut property)

setUseEchoSuppression (Microphone.setUseEchoSuppression method)

public setUseEchoSuppression(useEchoSuppression: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 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: ActionScript 1.0; Flash Player 6

Parameters

useEchoSuppression :Boolean - 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);

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

setUseEchoSuppression (Microphone.setUseEchoSuppression method), useEchoSuppression (Microphone.useEchoSuppression property)

silenceLevel (Microphone.silenceLevel property)

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: ActionScript 1.0; 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. 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.

See also

gain (Microphone.gain property), setSilenceLevel (Microphone.setSilenceLevel method)

silenceTimeOut (Microphone.silenceTimeOut property)

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: ActionScript 1.0; 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 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.

See also

setSilenceLevel (Microphone.setSilenceLevel method)

useEchoSuppression (Microphone.useEchoSuppression property)

public useEchoSuppression : Boolean [read-only]

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.

Availability: ActionScript 1.0; 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);

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

setUseEchoSuppression (Microphone.setUseEchoSuppression method)



ActionScript 2.0 Language Reference for Macromedia Flash 8
ActionScript 2.0 Language Reference for Macromedia Flash 8
ISBN: 0321384040
EAN: 2147483647
Year: 2004
Pages: 113

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net