I'm using dialogflow for speech recognition and intents, but when I get a response with the output audio, I can't find a way to play the audio response. The audio response comes in the format of some kind of array. The JSON object looks like this (It's the data parameter that I'm trying to convert to audio):
{
"type":"Buffer",
"data":[255,251,16,196,0,0,0,0,1,164,20,0,0,32,...]},
"latency":2906,
"fulfillmentMessages":["Here's your Adele playlist."],
"parameters":
{
"any":[],
"music-artist":["Adele"]},
"success":true
}
}
I already tried converting it to an ArrayBuffer and then decoding it, but that didn't seem to work either
playByteArray(byteArray) {
var arrayBuffer = new ArrayBuffer(byteArray.length);
var bufferView = new Uint8Array(arrayBuffer);
for (let i = 0; i < byteArray.length; i++) {
bufferView[i] = byteArray[i];
}
let context = new AudioContext();
context.decodeAudioData(
arrayBuffer,
function(buffer) {
this.play(buffer);
}.bind(this)
);
}
play(buf) {
// Create a source node from the buffer
let context = new AudioContext();
var source = context.createBufferSource();
source.buffer = buf;
// Connect to the final output node (the speakers)
source.connect(context.destination);
// Play immediately
source.start(0);
}
edit: This is a JSON example I get back from DialogFlow: https://drive.google.com/open?id=1Y2UegyJ9BEwL6AR77Skly7prA4UalsNM