Created
October 7, 2017 20:21
-
-
Save bryanjenningz/b183629546918f32bc837dbe3def551f 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
navigator.mediaDevices.getUserMedia({ audio: true }) | |
.then(stream => { | |
const mediaRecorder = new MediaRecorder(stream); | |
mediaRecorder.start(); | |
const audioChunks = []; | |
mediaRecorder.addEventListener("dataavailable", event => { | |
audioChunks.push(event.data); | |
}); | |
mediaRecorder.addEventListener("stop", () => { | |
const audioBlob = new Blob(audioChunks); | |
const audioUrl = URL.createObjectURL(audioBlob); | |
const audio = new Audio(audioUrl); | |
audio.play(); | |
}); | |
setTimeout(() => { | |
mediaRecorder.stop(); | |
}, 3000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment