Offline #

Generate a buffer by rendering all of the Tone.js code within the callback using the OfflineAudioContext. The OfflineAudioContext is capable of rendering much faster than real time in many cases. The callback function also passes in an offline instance of Context which can be used to schedule events along the Transport.


// render 2 seconds of the oscillator
Tone.Offline(() => {
	// only nodes created in this callback will be recorded
	const oscillator = new Tone.Oscillator().toDestination().start(0);
}, 2).then((buffer) => {
	// do something with the output buffer
	console.log(buffer);
});

// can also schedule events along the Transport
// using the passed in Offline Transport
Tone.Offline(({ transport }) => {
	const osc = new Tone.Oscillator().toDestination();
	transport.schedule(time => {
		osc.start(time).stop(time + 0.1);
	}, 1);
	// make sure to start the transport
	transport.start(0.2);
}, 4).then((buffer) => {
	// do something with the output buffer
	console.log(buffer);
});
Offline (
callback:(context) => Promise<void > | void ,

All Tone.js nodes which are created and scheduled within this callback are recorded into the output Buffer.

duration:Seconds ,

the amount of time to record for.

channels= 2:number ,
sampleRate= getContext().sampleRate:number
) => Promise<ToneAudioBuffer >
The promise which is invoked with the ToneAudioBuffer of the recorded output.