Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

45
Vistas
jQuery Scroll to the bottom of the page based on audio input

So i'm basically trying to control my site with my voice. I can currently make a changing number with the incoming audio input. With that number i want to decide whether my site has to scroll fast or slow. This number in fact, is constantly changing from around 1-200. Now i am stuck at getting the jQuery animate() function to constantly adjust its scrolling speed. Because now it seems its just maintaining the speed of the first number it gets.

This is my JavaScript code which is supposed to scroll the whole body of the page:

let actualNumb = Numb(function(numb) {
    if (numb >= 1 ) {
    $("html, body").animate(
            { scrollTop: $(document).height() }, numb * 1000
        );
    }
})

// Function to get audioinput and convert it to a number between 0 and 100:
navigator.mediaDevices.getUserMedia({ audio: true, video: false })
.then(function(stream) {
    // If audio object is created through promise, create audio-processor:
  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);

  // Function that gets processed every time it gets some audio input:
  javascriptNode.onaudioprocess = function() {
      console.log("Audio");
      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 = Math.round((values / length));

      console.log(average);
      actualNumb.setNumb(average);
  }
}).catch(function(err) {console.log(err)});


// Create function to observe the number that is constantly changing:
function Numb(callback) {
    let numb = 0;

    return {
        getNumb: function() { return numb; },
        setNumb: function(x) { numb = x; callback(numb); }
    };
}
7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.