Return to Snippet

Revision: 55663
at February 16, 2012 07:01 by tpryan


Initial Code
function playAudio(file, speed){	
	if (typeof AudioContext == "function") {
		var audioContext = new AudioContext();
	} else if (typeof webkitAudioContext == "function") {
		var audioContext = new webkitAudioContext();
	}

	var source = audioContext.createBufferSource();
	source.connect(audioContext.destination);


	var xhr = new XMLHttpRequest();
	xhr.open("GET", file, true);
	xhr.responseType = "arraybuffer";
	xhr.onload = function() {
		var buffer = audioContext.createBuffer(xhr.response, false);
		source.buffer = buffer;
		source.playbackRate.value = speed;
		source.noteOn(0);
	};
	xhr.send();
}

Initial URL


Initial Description
Code required to play an audio file using Web Audio API

Initial Title
Web Audio API code for loading audio at a particular speed.

Initial Tags


Initial Language
JavaScript