Created
April 8, 2020 12:42
-
-
Save savelee/e794f97dc7210942330c066f90e9a541 to your computer and use it in GitHub Desktop.
Client - Text to Speech - Streaming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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