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

225
Visualizações
(Javascript) Microphone and audio from mediastream are out of sync

I wrote a recorder that records microphone from getUsermedia and audio which is from local using Howler JS. I created mediastream destination, and connected each sources (mic, audio) to the destination. audio seems fine, but microphone is delayed about 2seconds. I can't figure out the problem. could you help me guys?

var recorder;
const stop = document.getElementsByClassName("stop");
const record = document.getElementsByClassName("record");

let mediaDest = Howler.ctx.createMediaStreamDestination();
Howler.masterGain.connect(mediaDest);
function onRecordingReady(e) {
  // 'e' has 'blob event'
  //var audio = document.getElementById("audio");
  audioBlob = e.data; // e.data has blob.
  //audio.src = URL.createObjectURL(e.data);
}

let audioBlob;
let audioURL = "";

navigator.mediaDevices.getUserMedia({ audio: true }).then(function (stream) {
  let userMic = Howler.ctx.createMediaStreamSource(stream);
  userMic.connect(mediaDest);
  Howler.masterGain.connect(mediaDest);
  recorder = new MediaRecorder(mediaDest.stream);
  recorder.addEventListener("dataavailable", onRecordingReady);
  recorder.addEventListener("stop", function () {
    W3Module.convertWebmToMP3(audioBlob).then((mp3blob) => {
      const downloadLink = document.createElement("a");
      downloadLink.href = URL.createObjectURL(mp3blob);
      downloadLink.setAttribute("download", "audio");
      //downloadLink.click();
      var audio = document.getElementById("audio");
      audio.src = URL.createObjectURL(mp3blob);
      console.log(mp3blob);
    });
  });
});

record[0].addEventListener("click", function () {
  recorder.start();
});

stop[0].addEventListener("click", function () {
  recorder.stop();
});
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I figured out the solution. I didn't know I could connect MediaStreamAudioSourceNode to GainNode. If someone is suffering this issue, just connect one Node to another Node rather than connect each node to the destination.

I connected the sourceNode to the GainNode, and connected GainNode to the destination.

========================= It was not the solution... GainNode playback in realtime whenever input is present...so, even if i can remove the latency, annoying playback occurs.

about 4 years ago · Santiago Trujillo Relatório
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