I'm experimenting with playing a wav file using the AudioContext. I've noticed that it plays correctly when loaded with the <audio>
tag (as demonstrated in this
example on jsFiddle), but encounters issues when using AudioContext.
var startButton = document.getElementById('start-stream');
var wav = new wavefile.WaveFile();
startButton.onclick = function() {
audioCtx = new AudioContext();
wav.fromBase64(mydata);
buffer = audioCtx.createBuffer(1, audioCtx.sampleRate * 3, audioCtx.sampleRate);
// add audio data to buffer
buffer.getChannelData(0).set(wav.getSamples());
source = audioCtx.createBufferSource();
source.buffer = buffer;
source.connect(audioCtx.destination);
source.start();
};
You can view the code on this fiddle: https://jsfiddle.net/Persiancoffee/6v8dLt3f/7/