title: saving wav at nodejs server
body: <p>I am trying to save a recorded audio to a audio file at server.</p>
  
  <p>Reference: <a href="http://www.smartjava.org/content/record-audio-using-webrtc-chrome-and-speech-recognition-websockets" rel="nofollow">http://www.smartjava.org/content/record-audio-using-webrtc-chrome-and-speech-recognition-websockets</a></p>
  
  <p>Code: </p>
  
  <pre><code>var rec;
  
  function testaudio(){
   navigator.getUserMedia({audio: true}, success, error);
  function success(stream){
      var context = new webkitAudioContext();
      console.log(context);
      console.log(context.source);
      console.log(context.destination);
              var mediaStreamSource = context.createMediaStreamSource(stream);
      console.log(mediaStreamSource);
              rec = new Recorder(mediaStreamSource);
      console.log(rec);
  }
  function error(e){console.log('error in testing audio.. !!1'+e);}   
  </code></pre>
  
  <p>}</p>
  
  <p>function record(){
      rec.record();</p>
  
  <pre><code>console.log("recording..");
  </code></pre>
  
  <p>}</p>
  
  <p>function stopAndSend()
  {</p>
  
  <pre><code>rec.stop();
  
  console.log("recording stopped!!!");
  rec.exportWAV(function(blob){
  
  console.log(blob);
      socket.emit('audioSave', {recordedData:blob}); //sending blob to server, socket is created using socket.io
  
  });
  </code></pre>
  
  <p>}</p>
  
  <p>server side code:</p>
  
  <pre><code>   socket.on('audioSave', function(data){
        var audio=data.recordedData;
        /*
        Here i want to save this audio in an audio file , i tried this
          fs.writeFile('out.wav', audio, function(err)
      {
          if(err) {console.log("!!!!!!!!!!!!!!!error in writing file..."+ err);}
  
          console.log(" Audio File created ");
      }
      );
             This method creates  text file
         */
     });
  </code></pre>
  
  <p>how can I write audio blob to an audio file?</p>