Skip to content

Instantly share code, notes, and snippets.

@generalsystems
Last active November 19, 2024 17:56
Show Gist options
  • Select an option

  • Save generalsystems/7a570e31368d0db033656501846c404a to your computer and use it in GitHub Desktop.

Select an option

Save generalsystems/7a570e31368d0db033656501846c404a to your computer and use it in GitHub Desktop.
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 = new Blob(await recorder.stop(), {type:'audio/mpeg-3'});
// download the recording by creating an anchor element and blob url
const url = URL.createObjectURL(recording);
const anchor = document.createElement("a");
anchor.download = "recording.mp3";
anchor.href = url;
anchor.click();
}, 4000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment