Skip to content

Instantly share code, notes, and snippets.

@savelee
Created April 8, 2020 12:42
Show Gist options
  • Save savelee/e794f97dc7210942330c066f90e9a541 to your computer and use it in GitHub Desktop.
Save savelee/e794f97dc7210942330c066f90e9a541 to your computer and use it in GitHub Desktop.
Client - Text to Speech - Streaming
// 1)
function playOutput(arrayBuffer){
let audioContext = new AudioContext();
let outputSource;
try {
if(arrayBuffer.byteLength > 0){
// 2)
audioContext.decodeAudioData(arrayBuffer,
function(buffer){
// 3)
audioContext.resume();
outputSource = audioContext.createBufferSource();
outputSource.connect(audioContext.destination);
outputSource.buffer = buffer;
outputSource.start(0);
},
function(){
console.log(arguments);
});
}
} catch(e) {
console.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment