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

167
Views
arraybuffor into audio src

I'm getting a arraybuffer from http response. The code below plays the audio just once but I want to to use audio as src for audio element!

    this.toSpeechService.getAudioFile(this.text).subscribe(res => {
       const context = new AudioContext();
       let source = context.createBufferSource();
       context.decodeAudioData(res, function(buffer) {
            source.buffer = buffer;
          }, null).then(() => {
            source.connect(context.destination);
            this.audioSrc = context.destination; // doesn't fill the audio player
            source.start(0);
       });
       console.log(res)
     });
    <audio controls="controls">
      <source [src]="audioSrc" type="audio/mp3/wav" />
       Your browser does not support the audio element.
    </audio>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In case you know the mime type of the data in the ArrayBuffer the following should work.

this.toSpeechService.getAudioFile(this.text).subscribe(res => {
    const blob = new Blob([ res ], { type: THE_MIME_TYPE });
    const url = URL.createObjectURL(blob);

    YOUR_AUDIO_ELEMENT.src = url;
    YOUR_AUDIO_ELEMENT.load();
});

THE_MIME_TYPE is a placeholder for the actual mimeType. And YOUR_AUDIO_ELEMENT is a reference to your audio element.

Once you don't need the object URL anymore you can release the memory by calling URL.revokeObjectURL(url).

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!