
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Read & write wave files with 4, 8, 16, 24, 32 & 64-bit data.
Copyright (c) 2017 Rafael da Silva Rocha.
https://github.com/rochars/wavefile
npm install wavefile
Hit "Load in player" to generate wave files.
let fs = require("fs");
let Wavefile = require("wavefile");
let wav = new Wavefile(fs.readFileSync("file.wav"));
console.log(wav.chunkId);
console.log(wav.chunkSize);
console.log(wav.fmtChunkId);
fs.writeFileSync(path, wav.toBuffer());
let wav = new WaveFile();
// mono
wav.fromScratch(1, 44100, '32', [0, -2147483648, 2147483647, 4]);
fs.writeFileSync(path, wav.toBuffer());
// stereo
wav.fromScratch(2, 48000, '8', [
[0, -2, 4, 3],
[0, -1, 4, 3]
]);
wav.interleave();
fs.writeFileSync(path, wav.toBuffer());
// Default is RIFF. To create RIFX files:
wav.fromScratch(1, 44100, '32', samples, {"container": "RIFX"});
fs.writeFileSync(path, wav.toBuffer());
Currently there is no dithering when changing the bit depth.
If the samples are stereo they need to be interleaved before changing the bit depth.
let wav = new Wavefile(fs.readFileSync("file.wav"));
// Possible values are:
// "8", "16", "24", "32", "32f", "64"
wav.toBitDepth("24");
// Interleave stereo samples
wav.interleave();
// De-interleave the samples into multiple channels
wav.deInterleave();
// Turn a RIFF file to a RIFX file
wav.toRIFX();
// Turn a RIFX file to a RIFF file
wav.toRIFF();
16-bit 8000 Hz wave files can be compressed as IMA-ADPCM:
// Encode a 16-bit wave file as 4-bit IMA-ADPCM:
wav.toIMAADPCM();
To decode 4-bit IMA-ADPCM as 16-bit PCM:
// Decode 4-bit IMA-ADPCM as 16-bit:
wav.fromIMAADPCM();
The decoder assumes a 256 block align. To use a different block align:
// Decode 4-bit IMA-ADPCM, 1024 blockalign:
wav.fromIMAADPCM(1024);
16-bit wave files can be encoded as A-Law:
// Encode a 16-bit wave file as 8-bit A-law:
wav.toALaw();
To decode 8-bit A-Law as 16-bit PCM:
// Decode 8-bit A-Law as 16-bit:
wav.fromALaw();
16-bit wave files can be encoded as mu-Law:
// Encode a 16-bit wave file as 8-bit A-law:
wav.toMuLaw();
To decode 8-bit mu-Law as 16-bit PCM:
// Decode 8-bit A-Law as 16-bit:
wav.fromMuLaw();
let wav = new Wavefile(fs.readFileSync("file.wav"));
// The container, "RIFF" or "RIFX"
console.log(wav.chunkId);
console.log(wav.chunkSize);
console.log(wav.format); // WAVE
// "fmt "
console.log(wav.fmtChunkId);
console.log(wav.fmtChunkSize);
console.log(wav.audioFormat);
console.log(wav.numChannels);
console.log(wav.sampleRate);
console.log(wav.byteRate);
console.log(wav.blockAlign);
console.log(wav.bitsPerSample);
console.log(wav.cbSize);
console.log(wav.validBitsPerSample);
// "fact"
console.log(wav.factChunkId);
console.log(wav.factChunkSize);
console.log(wav.dwSampleLength);
// "data"
console.log(wav.dataChunkId);
console.log(wav.dataChunkSize);
// array of numbers
console.log(wav.samples);
Range:
Copyright (c) 2017 Rafael da Silva Rocha.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Create, read and write wav files according to the specs.
The npm package wavefile receives a total of 54,562 weekly downloads. As such, wavefile popularity was classified as popular.
We found that wavefile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.