Since Flash Player 10.1, it is now possible to record the flow of the microphone as ByteArray, to listen, and then save it on your hard drive.
In fact, since Flash Player 10.1, using SampleDataEvent.SAMPLE_DATA, we may acquire in the raw stream from the microphone.
In this example, you can register, you listen, and then save the sound file in WAVE.
Code:
PHP Code:
import pack.WAVEncoder;
var soundBytes:ByteArray = new ByteArray();
soundBytes.endian = Endian.LITTLE_ENDIAN;
var mic:Microphone = Microphone.getMicrophone();
mic.gain = 100;
mic.rate = 44;
rec.addEventListener(MouseEvent.CLICK,onClickk);
function onClickk(e:Event):void
{
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
}
function micSampleDataHandler(event:SampleDataEvent):void
{
while (event.data.bytesAvailable)
{
var sample:Number = event.data.readFloat();
soundBytes.writeFloat(sample);
}
}
function playbackSampleHandler(event:SampleDataEvent):void
{
for (var i:int = 0; i < 8192 && soundBytes.bytesAvailable > 0; i++)
{
var sample:Number = soundBytes.readFloat();
event.data.writeFloat(sample);
event.data.writeFloat(sample);
}
}
eco.addEventListener(MouseEvent.CLICK,onClick);
function onClick(e:Event):void
{
mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
soundBytes.position = 0;
var sound:Sound = new Sound();
sound.addEventListener(SampleDataEvent.SAMPLE_DATA, playbackSampleHandler);
sound.play();
}
function _saveFileHandler(e:Event):void
{
var encoder:WAVEncoder = new WAVEncoder ( );
var fileRef:FileReference = new FileReference ( );
fileRef.save( encoder.addHeaders ( testConvert(soundBytes) ), "monSon.wav" );
}
function testConvert( p:ByteArray ):ByteArray
{
var ba:ByteArray = new ByteArray ( );
ba.endian = Endian.LITTLE_ENDIAN;
p.position = 0;
while ( p.position < p.length )
{
ba.writeShort( p.readFloat ( ) * 32767);
}
return ba;
}
mySaveButton.addEventListener(MouseEvent.CLICK,_saveFileHandler);