You need to save the data passed to you in gotMicData , in ByteArray , and then save ByteArray . You save the name of the event, which is a string (10 characters long).
Once you do this, you need to download the file and transfer the sample data to sound. You play sound 8 times ... because you tried it at 11 kHz, but the sound is played at 44 kHz (recording 4 times), and the sound is Stereo, but the microphone is mono (2x again).
You cannot save data as a WAV file directly ... you recorded raw data. If you want to solve the problem of recording the correct WAV header, you do not need to play games with the transfer of sample data and transfer the file to the Sound object. This is an exercise that goes beyond the scope of this question.
Good luck
import mx.controls.Alert; public var mic:Microphone = Microphone.getMicrophone(); public var recordedData:ByteArray; protected function startMicRecording():void { mic.gain = 60; mic.rate = 11; mic.setUseEchoSuppression(true); mic.setLoopBack(false); mic.setSilenceLevel(5, 1000); recordedData = new ByteArray(); mic.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData); } protected function stopMicRecording():void { mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData); try{ var file:FileReference = new FileReference(); file.save(recordedData, "recorded.dat" ); } catch(e:Error) { Alert.show("In Stopmicrecording"+e); } } private function gotMicData(sample:SampleDataEvent):void { recordedData.writeBytes(sample.data, 0, sample.data.bytesAvailable); } protected var playbackFile:FileReference; protected var soundRecording:ByteArray; protected var soundOutput:Sound; protected function playbackData():void { playbackFile = new FileReference(); playbackFile.addEventListener(Event.SELECT, playbackFileSelected); playbackFile.browse(); } private function playbackFileSelected(event:Event):void { playbackFile.addEventListener(Event.COMPLETE, playbackFileLoaded); playbackFile.load(); } private function playbackFileLoaded(event:Event):void { soundRecording = playbackFile.data; soundOutput = new Sound(); soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, moreInput); soundOutput.play(); } private function moreInput(event:SampleDataEvent):void { var sample:Number; for (var i:int = 0; i < 1024; i++) { if (soundRecording.bytesAvailable > 0) { sample = soundRecording.readFloat();
Brian genisio
source share