Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda