Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Weird rhythmic static when realtime audio streaming MediaStreamAPI

I have a small issue, This code below live streams audio from one client to another in the same room. This works by the first client sending audio data to the server which sends it to a separate client. When a different client receives the incoming audioData, the arraybuffer is changed to a float32array and then into an audio buffer that is then connected to an output device and played. The result of this is a realtime audio feed from one client to another. However, there is a static/click that seems to happen when one audiobuffer stops playing and the next one starts. However, when I increase the sample rate of the "audioC" audioContext, this static appears more frequently. Does anyone know why this is happening or how I can fix this?

const socket = io();
var AudioContext = window.AudioContext || window.webkitAudioContext;
const audioCtx = new AudioContext({
  latencyHint: 'interactive',
  sampleRate: 16384,
});
const audioC = new AudioContext()

    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia

    if (navigator.getUserMedia) {
      console.log('getUserMedia supported.')

      navigator.getUserMedia(
        { audio: true },
        stream => {
          const source = audioCtx.createMediaStreamSource(stream)
          const processor = audioCtx.createScriptProcessor(16384, 1, 1)

          source.connect(processor)
          processor.connect(audioCtx.destination)
          processor.onaudioprocess = e => {
              socket.emit('Voice', e.inputBuffer.getChannelData(0))
          }

          socket.on('Voice', msg => {
            var z = new Float32Array(msg, 0, 16384);
            console.log(z)
            const audioBuffer = new AudioBuffer({
              length: 16384,
              sampleRate: 16384 
            });
            audioBuffer.copyToChannel(z, 0, 0);
            const source = audioC.createBufferSource();
            source.buffer = audioBuffer;
            source.connect(audioC.destination);
            source.start();
          })
          audioCtx.resume()
        },
        err => console.error(err)
      )
    }

The server side just sends data to another client upon receiving the data.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!