Recording Audio

Must Read

Just post!

When recording, the device buffers the microphone input. Create a ByteArray object to store the audio data. Create a reference to the microphone and add a listener to the SampleDataEvent.SAMPLE_DATA event:

import flash.utils.ByteArray;
var bytes:ByteArray = new ByteArray();

var microphone:Microphone=Microphone.getMicrophone();
if (microphone!= null) {
microphone.gain = 100;
microphone.rate = 22;
microphone.setSilenceLevel(0, 4000);
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, recording);
function recording(event:SampleDataEvent):void {
while( {
var sample:Number =;

To stop the recording, remove the event listener. You can do this in code using a timer:

import flash.utils.Timer;
var timer:Timer = new Timer(5000);
timer.addEventListener(TimerEvent.TIMER, stopRecording);
function stopRecording(event:TimerEvent):void {
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, recording);

You can also let the user click a button to stop the recording. In this case, be aware of the memory and storage being used. You may want to prompt the user if the recording has been going on for more than a few seconds.

Previous articleThe Microphone
Next articlePlaying Back Audio
- Advertisement -

Latest News

Lampang: A Gateway to Northern Thailand’s Natural Beauty

Located in northern Thailand, Lampang is a charming city that is often overlooked by tourists. Despite its small size,...
- Advertisement -

More Articles Like This

- Advertisement -