Last active
November 19, 2024 17:56
-
-
Save generalsystems/7a570e31368d0db033656501846c404a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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