Quantcast
Channel: Adobe Community: Message List
Viewing all articles
Browse latest Browse all 92756

Re: microphone record, playback in AIR html js desktop app

$
0
0

this works on my macbook. But on my Windows 8.1 machine the audio gets played back twice as slow as normal.

Not a lower pitch, just twice as slow. Any idea why this is?

 

$(function(){

    var s;

    var sc;

    var nowRecording = false;

    var nowPlaying = false;

    var recordedBytes = new air.ByteArray();

 

 

//   air.SoundMixer.audioPlaybackMode = window.runtime.flash.media.AudioPlaybackMode.VOICE

   

    var mic = air.Microphone.getMicrophone();

    mic.rate = 44;

    mic.gain = 70;

    mic.setSilenceLevel(0);

 

 

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

        if (!nowRecording) {

            air.trace("recording");

            recordedBytes.clear();

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

            nowRecording = true;

            $(this).val("Click me to stop")

        }

        else {

            air.trace("recording stopped");

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

            nowRecording = false;

            $(this).val("Click me to record")

        }

    })

   

    function getMicAudio(e){

        recordedBytes.writeBytes(e.data);

    }

   

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

        if (!nowPlaying) {

            air.trace("playing");

            recordedBytes.position = 0;

  s = new air.Sound();

            s.addEventListener(air.SampleDataEvent.SAMPLE_DATA, playAudio);

  sc = new air.SoundChannel

            s.play();

           sc.addEventListener(air.Event.SOUND_COMPLETE, stopPlayback, false, 0, true);

            nowPlaying = true;

          //  $(this).val("Click me to stop playing")

        }

        else {

            sc.stop();

            stopPlayback();

        }

    })

   

    function stopPlayback(e){

        air.trace("playing stopped");

        s.removeEventListener(air.SampleDataEvent.SAMPLE_DATA, playAudio);

        nowPlaying = false;

    }

   

    function playAudio(e){

 

  if(!recordedBytes.bytesAvailable > 0)

  return;

 

        for (var i = 0; i < 8192; i++) {

            var sample = 0;

 

  if(recordedBytes.bytesAvailable > 0) sample = recordedBytes.readFloat()

            e.data.writeFloat(sample);

            e.data.writeFloat(sample);

        }

    }

   

});


Viewing all articles
Browse latest Browse all 92756

Trending Articles



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