To
conserve bandwidth and processing resources, the runtime tries to
detect when a microphone transmits no sound. When the microphone’s
activity level stays below the silence level threshold for a period
of time, the runtime stops transmitting the audio input and dispatches
an
activity
event. If you use the Speex codec (available
in AIR 1.5), set the silence level to 0, to ensure that the application
continuously transmits audio data. Speex voice activity detection automatically
reduces bandwidth.
Three properties of the Microphone class monitor and control
the detection of activity:
-
The read-only
activityLevel
property
indicates the amount of sound the microphone is detecting, on a
scale from 0 to 100.
-
The
silenceLevel
property specifies the
amount of sound needed to activate the microphone and dispatch an
activity
event.
The
silenceLevel
property also uses a scale from
0 to 100, and the default value is 10.
-
The
silenceTimeout
property describes the
number of milliseconds that the activity level must stay below the
silence level before an
activity
event is dispatched.
The default
silenceTimeout
value is 2000.
Both the
Microphone.silenceLevel
property and
the
Microphone.silenceTimeout
property are read
only, but their values can be changed by using the
Microphone.setSilenceLevel()
method.
In some cases, the process of activating the microphone when
new activity is detected can cause a short delay. Keeping the microphone
active at all times can remove such activation delays. Your application
can call the
Microphone.setSilenceLevel()
method
with the
silenceLevel
parameter set to zero. This
keeps the microphone active and gathering audio data, even when
no sound is detected. Conversely, setting the
silenceLevel
parameter
to 100 prevents the microphone from being activated at all.
The following example displays information about the microphone
and reports on
activity
events and
status
events
dispatched by a Microphone object:
var deviceArray = air.Microphone.names;
air.trace("Available sound input devices:");
for (i = 0; i < deviceArray.length; i++)
{
air.trace(" " + deviceArray[i]);
}
var mic = air.Microphone.getMicrophone();
mic.gain = 60;
mic.rate = 11;
mic.setUseEchoSuppression(true);
mic.setLoopBack(true);
mic.setSilenceLevel(5, 1000);
mic.addEventListener(air.ActivityEvent.ACTIVITY, this.onMicActivity);
var micDetails = "Sound input device name: " + mic.name + '\n';
micDetails += "Gain: " + mic.gain + '\n';
micDetails += "Rate: " + mic.rate + " kHz" + '\n';
micDetails += "Muted: " + mic.muted + '\n';
micDetails += "Silence level: " + mic.silenceLevel + '\n';
micDetails += "Silence timeout: " + mic.silenceTimeout + '\n';
micDetails += "Echo suppression: " + mic.useEchoSuppression + '\n';
air.trace(micDetails);
function onMicActivity(event)
{
air.trace("activating=" + event.activating + ", activityLevel=" +
mic.activityLevel);
}
When you run the preceding example, speak or make noises into
your system microphone and watch the resulting trace statements
appear in the console.