Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

How to play audio from Buffer

$
0
0

@beck24 wrote:

I'm building an integration with AWS Lex and the API returns an audio response in the form of a Buffer

I've been spinning my wheels failing to find a way to play the audio response. Anyone have any idea?
Here's what I've got so far. It's not throwing any errors, but it's not playing any audio.

               var AudioContext = window.AudioContext // Default
                || window.webkitAudioContext // Safari and old versions of Chrome
                || false;

                let context = new AudioContext();
                let playSound = context.createBufferSource();

                // transform the aws Buffer response to an ArrayBuffer
                let ab = new ArrayBuffer(awsres.audioStream.length);
                let view = new Uint8Array(ab);
                for (let i = 0; i < awsres.audioStream.length; ++i) {
                  view[i] = awsres.audioStream[i];
                }

                context.decodeAudioData(ab, (buf) => {
                  playSound.buffer = buf;
                });
                playSound.connect(context.destination);
                console.log('playing sound');
                playSound.start(0);

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>