Skip to content

Instantly share code, notes, and snippets.

@bang9
Last active March 4, 2021 07:53
Show Gist options
  • Save bang9/637655131120b37bbf76c392d1ef99a8 to your computer and use it in GitHub Desktop.
Save bang9/637655131120b37bbf76c392d1ef99a8 to your computer and use it in GitHub Desktop.
webm to wav on react
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