Skip to content

Instantly share code, notes, and snippets.

View Daninet's full-sized avatar
🛠️
Focusing

Dani Biró Daninet

🛠️
Focusing
View GitHub Profile
@Daninet
Daninet / wav.js
Created July 2, 2022 13:57
Convert AudioBuffer's Float32Array to Wav file format
/** @param sampleRate {number} */
/** @param channelBuffers {Float32Array[]} */
function audioBufferToWav(sampleRate, channelBuffers) {
const totalSamples = channelBuffers[0].length * channelBuffers.length;
const buffer = new ArrayBuffer(44 + totalSamples * 2);
const view = new DataView(buffer);
const writeString = (view, offset, string) => {
for (let i = 0; i < string.length; i++) {