Streaming Large Audio Files for Web Audio API
The <audio>
element is the way to go, as it handles streaming and buffering under the hood. As of Chrome 18, you can use <audio>
elements as input sources for further processing with createMediaElementSource()
. Check out more information here:
http://updates.html5rocks.com/2012/02/HTML5-audio-and-the-Web-Audio-API-are-BFFs
This doesn't directly answer your question but it will be helpful.
An asynchronous decodeAudioData
method was added to the API. That will still use XHR, but it's worth switching your code over to it. The new method is available in Chrome 14.
// Use async decoder if it is available.if (context.decodeAudioData) { context.decodeAudioData(arrayBuffer, function(buffer) { source.buffer = buffer; }, function(e) { console.log(e); });} else { source.buffer = context.createBuffer(arrayBuffer, false);}