Last active
March 4, 2021 07:53
-
-
Save bang9/637655131120b37bbf76c392d1ef99a8 to your computer and use it in GitHub Desktop.
webm to wav on react
This file contains 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 toWav = require('audiobuffer-to-wav') | |
const audioContext = new (window.AudioContext || window.webkitAudioContext)() | |
const fileReader = new FileReader() | |
function download(blob){ | |
const url = window.URL.createObjectURL(blob) | |
const anchor = document.createElement('a') | |
anchor.href = url | |
anchor.download = 'audio.wav' | |
anchor.click() | |
} | |
fileReader.onloadend = () => { | |
const arrayBuffer = fileReader.result | |
audioContext.decodeAudioData(arrayBuffer, (audioBuffer) => { | |
const wav = toWav(audioBuffer) | |
const blob = new window.Blob([ new DataView(wav) ], { | |
type: 'audio/wav' | |
}) | |
download(blob); | |
}) | |
} | |
fileReader.readAsArrayBuffer(blobFromReactMic) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment