1 Reply Latest reply on Mar 31, 2011 2:25 AM by JabbyPandaUA

    Microphone playback with SPEEX codec in Flex


      Hey Guys, i am working on a project where the user  have to record his/her voice, and submit it to server. But before  submitting the user might need to play the recorded sound.

      The application has a recording and playing capabilities with SPEEX codec.  But what i found strange and difficult is when i the user plays back the recorded audio,  the playing speed is faster or slower than normal that it cannot be  understood. As if its fast forwarding.

      Here is the sample come:


      private var mic:Microphone;
      private var rec:ByteArray;
      private var snd:Sound;
      private var channel:SoundChannel;


      protected function recBtn_clickHandler(event:MouseEvent):void {

       rec = new ByteArray();
      mic = Microphone.getMicrophone();
      mic.gain = 50;
      mic.setSilenceLevel(5, 1000);
      mic.codec = SoundCodec.SPEEX; 

      mic.addEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio); 



      protected function plyBtn_clickHandler(event:MouseEvent):void {

       snd.addEventListener(SampleDataEvent.SAMPLE_DATA, playRecorded);  

      channel = snd.play();             



      private function getMicAudio(e:SampleDataEvent): void




      private function playRecorded(e:SampleDataEvent): void {

       if (!rec.bytesAvailable > 0) return;

      for (var i:int = 0; i < 2048; i++){
            var sample:Number = 0; 
            if (rec.bytesAvailable > 0) sample = rec.readFloat();

            for (var j:uint = 0; j < 6; j++) {


      This scenario only happens when:

      1. mic.codec = SoundCodec.SPEEX;
      2. mic.rate = 16

      I went through a lot of forums, but could not find any solution for  Microphone playback with SPEEX codec or microphone.rate = 16;

      If u have any solution or an idea...pls let me know asap!