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);Constructor
Section titled “Constructor”new Recorder(options?: Partial<RecorderOptions>)Parameters
- options
Partial<RecorderOptions>optional
Properties
Section titled “Properties”read-only
input: GainThe input node or nodes. If the object is a source, it does not have any input and this.input is undefined.
output
Section titled “output”read-only
output: undefinedThe output nodes. If the object is a sink, it does not have any output and this.output is undefined.
mimeType
Section titled “mimeType”read-only
mimeType: stringThe mime type is the format that the audio is encoded in. For Chrome that is typically webm encoded as “vorbis”.
read-only
state: PlaybackStateGet the playback state of the Recorder, either “started”, “stopped” or “paused”
supported
Section titled “supported”static read-only
supported: booleanTest 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].
Methods
Section titled “Methods”start()
Section titled “start()”start(): Promise<void>Start/Resume the Recorder. Returns a promise which resolves when the recorder has started.
Returns Promise<void>
stop()
Section titled “stop()”stop(): Promise<Blob>Stop the recorder. Returns a promise with the recorded content until this point encoded as mimeType
Returns Promise<Blob>
getDefaults()
Section titled “getDefaults()”static
getDefaults(): RecorderOptionsReturns all of the default options belonging to the class.
Returns RecorderOptions
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), set(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, version, disposed, toString() - From
ToneAudioNode: channelCount, channelCountMode, channelInterpretation, numberOfInputs, numberOfOutputs, chain(), connect(), disconnect(), fan(), toDestination(), toMaster()