Skip to content

Instantly share code, notes, and snippets.

@Narigo
Created February 4, 2022 00:55
Show Gist options
  • Save Narigo/08bae596e8e99d9828c407ea6c64ea3c to your computer and use it in GitHub Desktop.
Save Narigo/08bae596e8e99d9828c407ea6c64ea3c to your computer and use it in GitHub Desktop.
Poor man's recorder - to be used in browsers dev tools; start with recorder.record(); and stop with recorder.stop();
let recorder = await navigator.mediaDevices
.getUserMedia({ audio: true })
.then((mediaSourceObject) => {
document.createElement("audio").srcObject = mediaSourceObject;
const recorder = new MediaRecorder(mediaSourceObject);
let data = [];
recorder.ondataavailable = (e) => data.push(e.data);
recorder.onstop = () => {
const blob = new Blob(data, { type: "audio/ogg" });
data = [];
console.log(window.URL.createObjectURL(blob));
};
return {
record() {
recorder.start();
},
stop() {
recorder.stop();
},
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment