Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
Prevent addEventListener() run

I have a function that runs speech recognition when I click button start, when speech recognition is over some actions should be started. I use addEventListener('audioend', ()=>...) to track the event. Everything work as expected, but now I am adding another functionality to stop listening when I click the same button and the function should be completed also. But I faced an issue with addEventListener that runs despite the return key word.

const recognition = new SpeechRecognition.getRecognition()
const [isPlaying, setIsPlaying] = useState(false)

  function playSong() {
    setIsPlaying(!isPlaying) //when I click 'Play' button again it changes to 'Stop'
    if (listening) { //verify if speech recognition listening 
      SpeechRecognition.stopListening()
      console.log('Should stop here') 
      return   //I try to use return but it doesn't help, in any case addEventListener runs next
    }else if {
      recognition.addEventListener('audioend', () => {
      console.log('Some other actions')
    }
   ........
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of return you need to remove the event listener

const dosomeaction = () => {

    console.log("do some action")
};
recognition.addEventListener('audioend', dosomeaction)

In this way you add the event listiner so you can remove it by this way

recognition.removeEventListener('audioend', dosomeaction)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda