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

166
Views
web audio api and nested functions

I try to create an audiobuffer whose length depends on the length/duration of the audiofile.

I use the web Audio API https://webaudio.github.io/web-audio-api/#offlineaudiocontext

 function getDuration(filename) {
        // Send XHR request for audio file to server.
            const request = new XMLHttpRequest();
            request.open('GET', gorilla.stimuliURL(filename));
            request.responseType = 'arraybuffer';
            request.onload = function() {
                    // Decode the audio.
                audioContext.decodeAudioData(request.response, function(buffer) {
                        // Load and arm the source buffer.
                    var tStimNew = buffer.duration;
                });
            }
            request.send();
        }  

I get the duration of the audiofile using this function. I tested it and tStimNew is exactly what I expected. The problem seems to be that the variable tStimNew is only local to the function. But I would like to have the variable global to be able to use it further.

Where/how exactly do I have to include a return? The nesting of the three functions makes it too complex for me.

Thank you in advance!

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!