Skip to content

Instantly share code, notes, and snippets.

@mheap
Created May 27, 2018 12:31
Show Gist options
  • Save mheap/48dacc2517cb4b6ce95597c5369b9a93 to your computer and use it in GitHub Desktop.
Save mheap/48dacc2517cb4b6ce95597c5369b9a93 to your computer and use it in GitHub Desktop.

A wav file is a file with an audio header, then slices of pcm audio. To create a wav file from PCM, you need to add a wav header with the correct sample rate

// npm install waveheader
const fs = require("fs");
const header = require("waveheader");
const filename = 'file.wav';
fs.writeFileSync(filename, header(0, {sampleRate: "16000"}); // 16000 khz
fs.appendFileSync(filename, fs.readFileSync('audio.pcm'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment