Question

I'm making a audio recorder with Adobe Flex (Microphone, NetStream), I want to get the current audio wave from Microphone to display in the visualization area, any idea how can i get the data?

Was it helpful?

Solution

You'll need to be using Flash Player 10 as I think that's the first time you actually got access to to the Microphone apis.

Then there's a simple function you can call which will get the microphone data:

private var soundBytes:ByteArray    = new ByteArray;
SoundMixer.computeSpectrum(soundBytes, false);

I usually call the computeSpectrum code in an enter frame handler and draw out the wave form from there.

Edit: I don't want to mislead you. I think the above code is for a pre-recorded audio file. If you want to user the microphone in flash 10. You do it like this:

private var _mic:Microphone;
_mid = Microphone.getMicrophone();
_mic.addEventListener( SampleDataEvent.SAMPLE_DATA, onSampleData );

protected function onSampleData( event:SampleDataEvent ):void {
    while( event.data.bytesAvailable ){
        var n:Number = event.data.readFloat();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top