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

147
Views
Impedir la ejecución de addEventListener()

Tengo una función que ejecuta el reconocimiento de voz cuando hago clic en el botón de start , cuando el reconocimiento de voz finaliza, se deben iniciar algunas acciones. Yo uso addEventListener('audioend', ()=>...) para rastrear el evento. Todo funciona como se esperaba, pero ahora estoy agregando otra funcionalidad para dejar de escuchar cuando hago clic en el mismo botón y la función también debería completarse. Pero enfrenté un problema con addEventListener que se ejecuta a pesar de la palabra clave de return .

 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 answers
Answer question

0

En lugar de regresar, debe eliminar el detector de eventos

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

De esta manera agregas el listiner de eventos para que puedas eliminarlo de esta manera.

 recognition.removeEventListener('audioend', dosomeaction)
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!