如何从麦克风录制声音并从以下代码中保存
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.net.FileReference;
import mx.controls.Alert;
import flash.net.FileReference;
[Bindable] private var microphoneList:Array;
protected var microphone:Microphone;
protected var isRecording:Boolean = false;
protected function setupMicrophoneList():void
{
microphoneList = Microphone.names;
}
protected function setupMicrophone():void
{
microphone = Microphone.getMicrophone(comboMicList.selectedIndex);
}
protected function startMicRecording():void
{
Alert.show("In recording");
isRecording = true;
Alert.show("In recording1");
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
Alert.show("In recording22");
}
protected function stopMicRecording():void
{
isRecording = false;
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
private function gotMicData(micData:SampleDataEvent):void
{
Alert.show("In mic data");
// micData.data contains a ByteArray with our sample. }
try{
var file:FileReference = new FileReference();
file.save(micData.data ,"Testsound.flv");
}
catch(e:Error)
{
Alert.show("In gotomicdataexception"+e);
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:ComboBox x="150" id="comboMicList" dataProvider="{microphoneList}" />
<mx:Button x="250" id="startmicrec" label="Start Rec" click="startMicRecording()"/>
<mx:Button x="350" id="stopmicrec" label="Stop Rec" click="stopMicRecording()"/>
<mx:Button x="50" id="setupmic" label="Select Mic" click="setupMicrophone()"/>
<mx:Button x="450" id="playrecsound" label="Play sound" click="playbackData()"/>