микрофон.addEventListener (SampleDataEvent.SAMPLE_DATA, gotMicData);
событие gotMicData никогда не запускается .. однако я попытался использовать dispatchEvent, но это вернет null byteArray ..
Однако подобный код прекрасно работает в Flashcs5 ...
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.media.Sound;
import flash.utils.ByteArray;
[Bindable] private var microphoneList:Array;
protected var microphone:Microphone;
protected var isRecording:Boolean = false;
protected var soundRecording:ByteArray;
protected var soundOutput:Sound;
protected function setupMicrophoneList():void
{
microphoneList = Microphone.names;
}
protected function setupMicrophone():void
{
microphone = Microphone.getMicrophone(comboMicList.selectedIndex);
microphone.rate = 44;
}
protected function startMicRecording():void
{
isRecording = true;
soundRecording = new ByteArray();
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
protected function stopMicRecording():void
{
isRecording = false;
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
private function gotMicData(micData:SampleDataEvent):void
{
soundRecording.writeBytes(micData.data);
}
protected function playbackData():void
{
soundRecording.position = 0;
soundOutput = new Sound();
soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, playSound);
soundOutput.play();
}
private function playSound(soundOutput:SampleDataEvent):void
{
if (!soundRecording.bytesAvailable > 0)
return;
for (var i:int = 0; i < 8192; i++)
{
var sample:Number = 0;
if (soundRecording.bytesAvailable > 0)
sample = soundRecording.readFloat();
soundOutput.data.writeFloat(sample);
soundOutput.data.writeFloat(sample);
}
}
]]>
</mx:Script>