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

118
Views
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
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!