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

127
Views
how do I keep playing audio file in browser

I am trying to play audio clips of audio receieved from server through socketio. The code works but on the first audio clip recieved is played, any clip recieved afterwards are not played. I confirmed their reciept but I don't know why it only plays the first received audio file.


   socketio.on('audio_playback_results', function (data) {
        console.log("I recieved an audio playback! ",data);
        playOutput(data);
    });


    function playOutput(arrayBuffer){
        let audioContext = new AudioContext();
        let outputSource;
        try {
            if(arrayBuffer.byteLength > 0){
                console.log(arrayBuffer.byteLength);
                audioContext.decodeAudioData(arrayBuffer,
                function(buffer){
                    audioContext.resume();
                    outputSource = audioContext.createBufferSource();
                    outputSource.connect(audioContext.destination);
                    outputSource.buffer = buffer;
                    outputSource.start(0);
                },
                function(){
                    console.log(`playoutput PLAYING OUTPUT ARGUMMENT ${arguments}`);

                    // console.log(arguments);
                });
            }
        } catch(e) {

            console.log(`ERORRR PLAYING OUTPUT ${e}`);
        }
    }

i perform a text to audiobuffer on server side and then stream it back to client side.

async function textToAudioBuffer(text) {

  requestTTS.input = { text: text }; // text or SSML
    const response = await ttsClient.synthesizeSpeech(requestTTS);
    console.log("RESPONSE @ ttsClient, textToAudioBuffer() : ", response[0].audioContent)

    var results = response[0].audioContent

     io.emit('audio_playback_results', results);


  return response[0].audioContent;
}

what is causing it not to play audio clip recieved after the first one and how can I fix this ?

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!