I am trying to play a wav file using AudioContext - it plays correctly when loaded with <audio>
tag (as shown in jsfiddle), but plays incorrectly 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();
};
Fiddle is here: https://jsfiddle.net/Persiancoffee/6v8dLt3f/7/