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

119
Vistas
Audio ended event on iOS not triggered when streaming audio from NodeJS

I am using @google-cloud/text-to-speech to stream some audio.

Here is the code in the backend:

import { TextToSpeechClient } from '@google-cloud/text-to-speech';
const t2s = new TextToSpeechClient();

app.use('/api/v1/text2speech', async (req, res) => {
    const text = req.query['text'];
    const t2s = new TextToSpeechClient();
    const request = { input: { text }, audioConfig: { audioEncoding: 2 } };
    const [response] = await t2s.synthesizeSpeech(request);
    res.setHeader('Content-Type', 'audio/mpeg');
    res.write(response.audioContent);
    return res.end();
});

In the browser:

<audio src="/api/v1/text2speech?text=Audio to be played"></audio>

Attempt to do something on the audio ended event:

const audio = document.querySelector('audio');
audio.addEventListener('ended', () => {
    // Nothing happens here on iOS/iPad OS
    window.alert('Audio has ended');
});

Result: Works on all devices except iOS/iPad OS

Notes:

  1. The ended even does get triggered when the audio is played from a static file. But I need to stream the audio & not play from a file.
  2. I have also tried workarounds to check the status of audio.paused but the audio.paused property remains false forever, even though the stream has completed.
  3. Since this is a stream, I do not know the duration of the audio. So I can't check the value based on currentTime.
about 4 years 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 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