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

155
Visualizações
Defining a function and a variable in HTML5 audio code

I am not a programmer, I'm just trying to make a project for my work. I tried to learn some Javascript 10 years ago, but I haven't been working with programming since that time. The question is simple for real programmers.

I've found some code that shows the level of audio from microphone input. What do I need to do:

  • define a function to execute this code (or a part of it). This function must return this number: console.log(Math.round(average)).
  • define a variable that takes the result of this function so that I should be able to take this variable and pass it to another function.

Thank you.

navigator.mediaDevices.getUserMedia({ audio: true }).then(function(stream) {
  audioContext = new AudioContext();
  analyser = audioContext.createAnalyser();
  microphone = audioContext.createMediaStreamSource(stream);
  javascriptNode = audioContext.createScriptProcessor(2048, 1, 1);
  analyser.smoothingTimeConstant = 0.8;
  analyser.fftSize = 1024;
  microphone.connect(analyser);
  analyser.connect(javascriptNode);
  javascriptNode.connect(audioContext.destination);
  javascriptNode.onaudioprocess = function() {
      var array = new Uint8Array(analyser.frequencyBinCount);
      analyser.getByteFrequencyData(array);
      var values = 0;

      var length = array.length;
      for (var i = 0; i < length; i++) {
        values += (array[i]);
      }

      var average = values / length;

      if(Math.round(average)>15)
      {
        console.log(Math.round(average));
        document.getElementById("lvl").innerHTML = Math.round(average)-10;
      }
    
  }
  })
  .catch(function(err) {
    /* handle the error */
});

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