Quantcast
Channel: Adobe Community : All Content - AIR Development
Viewing all articles
Browse latest Browse all 2954

microphone record, playback in AIR html js desktop app

$
0
0

hi,

I want to record, save and playback the microphone audio in an HTML/JS AIR desktop app.

I can't find any examples so my code is based on AS3.

But the app crashes almost right away when the SampleDataEvent handler function is called.

Should it be in a while loop sames as AS3?

 

$(function(){

    var mic;

    var soundBytes = new air.ByteArray();

  

    $("#btnRecord").click(function(){

        mic = air.Microphone.getMicrophone();

        mic.rate = 44;

        mic.addEventListener(air.SampleDataEvent.SAMPLE_DATA, sampleEvent);

    })

 

  

    function sampleEvent(e){

        while (e.data.bytesAvailable) {

            var sample = e.data.readFloat();

            soundBytes.writeFloat(sample);

        }

    }


    $("#btnStop").click(function(){

        mic.removeEventListener(air.SampleDataEvent.SAMPLE_DATA, sampleEvent);

        $("#txtActivity").val("");

    })

  

    $("#btnPlay").click(function(){;

        for (var i = 0; i < 8192 && soundBytes.bytesAvailable > 0; i++) {

            var sample = soundBytes.readFloat();

            e.data.writeFloat(sample);

            e.data.writeFloat(sample);

            //we write the data twice because there are 2 channels (stereo)

        }

    })

 

 

  

}

thanks,

Jeff.


Viewing all articles
Browse latest Browse all 2954

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>