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

245
Views
Intentando detectar cuándo finaliza el audio del oscilador (javascript)

Estoy tratando de detectar cuándo el audio del oscilador ha dejado de reproducirse. Cuando uso onended, onend o event listener, solo se detecta cuando ejecuto oscillator.stop()

¿Alguien tiene alguna idea de lo que estoy haciendo mal o cómo se puede hacer esto? Gracias por adelantado.

El código del oscilador es el siguiente:

 let AudioContext = window.AudioContext || window.webkitAudioContext; let ctx = new AudioContext(); let dot = 1.2 / 15; function morsecode_audio_play() { morsecode_textToSpeech_stop() document.querySelector('#play_audio_button_morse').innerHTML = '<button id="stop_audio_morse">⏹️</button>'; document.querySelector('#stop_audio_morse').addEventListener('click', morsecode_audio_stop); oscillator = ctx.createOscillator(); let t = ctx.currentTime; oscillator.type = "sine"; oscillator.frequency.value = 600; let gainNode = ctx.createGain(); gainNode.gain.setValueAtTime(0, t); let morsecode = inputMorse.value.split(""); morsecode.forEach(function(letter) { switch(letter) { case ".": gainNode.gain.setValueAtTime(1, t); t += dot; gainNode.gain.setValueAtTime(0, t); t += dot; break; case "-": gainNode.gain.setValueAtTime(1, t); t += 3 * dot; gainNode.gain.setValueAtTime(0, t); t += dot; break; case " ": t += 7 * dot; break; } }); oscillator.connect(gainNode); gainNode.connect(ctx.destination); oscillator.start(); oscillatorStatus = true; oscillator.addEventListener('ended', () => { console.log('oscillator ended'); morsecode_audio_load(); }) return false; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Logré resolverlo usando el tiempo de duración del sonido del oscilador.

El tiempo es almacenado por el foreach en una variable t para el tiempo. Usé esa variable en un temporizador para detectar el final.

 setTimeout(function(){ morsecode_audio_stop(); t = 0; }, t*1000);
about 4 years ago · Juan Pablo Isaza Report
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!