title: JS - Play audio from buffers
body: <p>I have a python script that generates an audio buffer every 170 ms.
  This buffer is sent in real time to my JS program through a socket.
  I'm now trying to play the sound of the buffers in real time.</p>
  
  <p>I tried to create a new JS AudioBuffer every time I receive something but doing leads to a lot of stuttering.</p>
  
  <pre><code>var net = require('net');
  var client = new net.Socket();
  
  client.connect(8484, '127.0.0.1', function() {
      console.log('Connected');
  });
  
  var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
  var channels = 1;
  
  client.on('data', function(data) {
    // clean data (each buffer has a length of 1350)
    var array = String(data).split(";");
    for (var i = 0; i &lt; array.length; i++)
      array[i] = parseFloat(array[i])
    // play the small buffer
    var buf = audioCtx.createBuffer(channels, array.length, 16000);
    var buffering = buf.getChannelData(0);
    for (var i = 0; i &lt; array.length; i++)
        buffering[i] = array[i];
    var source = audioCtx.createBufferSource();
    source.buffer = buf;
    source.connect(audioCtx.destination);
    source.start();
  });
  </code></pre>
  
  <p>I also tried web-audio-stream API but it showed an error message.</p>
  
  <p>Thank you</p>