Skip to content
Tone.js

Recorder

class Component ↳ extends ToneAudioNode<RecorderOptions>

A wrapper around the MediaRecorder API. Unlike the rest of Tone.js, this module does not offer any sample-accurate scheduling because it is not a feature of the MediaRecorder API. This is only natively supported in Chrome and Firefox. For a cross-browser shim, install audio-recorder-polyfill.

const recorder = new Tone.Recorder();
const synth = new Tone.Synth().connect(recorder);
// start recording
recorder.start();
// generate a few notes
synth.triggerAttackRelease("C3", 0.5);
synth.triggerAttackRelease("C4", 0.5, "+1");
synth.triggerAttackRelease("C5", 0.5, "+2");
// wait for the notes to end and stop the recording
setTimeout(async () => {
	// the recorded audio is returned as a blob
	const recording = await recorder.stop();
	// download the recording by creating an anchor element and blob url
	const url = URL.createObjectURL(recording);
	const anchor = document.createElement("a");
	anchor.download = "recording.webm";
	anchor.href = url;
	anchor.click();
}, 4000);
new Recorder(options?: Partial<RecorderOptions>)

Parameters

read-only

input: Gain

The input node or nodes. If the object is a source, it does not have any input and this.input is undefined.

read-only

name: "Recorder"

The name of the class

Default: "Recorder"

read-only

output: undefined

The output nodes. If the object is a sink, it does not have any output and this.output is undefined.

read-only

mimeType: string

The mime type is the format that the audio is encoded in. For Chrome that is typically webm encoded as “vorbis”.

read-only

Get the playback state of the Recorder, either “started”, “stopped” or “paused”

static read-only

supported: boolean

Test if your platform supports the Media Recorder API. If it’s not available, try installing this (polyfill)[https://www.npmjs.com/package/audio-recorder-polyfill].

dispose(): this

Dispose and disconnect

Returns this

pause(): this

Pause the recorder

Returns this

start(): Promise<void>

Start/Resume the Recorder. Returns a promise which resolves when the recorder has started.

Returns Promise<void>

stop(): Promise<Blob>

Stop the recorder. Returns a promise with the recorded content until this point encoded as mimeType

Returns Promise<Blob>

static

getDefaults(): RecorderOptions

Returns all of the default options belonging to the class.

Returns RecorderOptions