dotwav
v0.1.0
Published
Warning: This is a work in progress and the API isn't currently stable yet!
Downloads
1
Readme
Warning: This is a work in progress and the API isn't currently stable yet!
Motivation
Needed a lib that provided both an encode and a decode function compatible with Typescript and with a simple API. Couldn't find exactly what I wanted so I adapted some code mainly from mohayonao/wav-encoder and mohayonao/wav-decoder.
Get started
Install
npm install --save unit-fns
# or
yarn add unit-fns
Use
import { encode, decode } from 'dotwav'
const fs = require('fs')
const whiteNoise1sec = {
sampleRate: 44100,
channelData: [
new Float32Array(44100).map(() => Math.random() - 0.5),
new Float32Array(44100).map(() => Math.random() - 0.5),
],
}
fs.writeFileSync('noise.wav', new Buffer(encode(whiteNoise1sec)))
const readFile = filepath => {
return new Promise((resolve, reject) => {
fs.readFile(filepath, (err, buffer) => {
if (err) {
return reject(err)
}
return resolve(buffer)
})
})
}
readFile('noise.wav').then(buffer => {
const audioData = decode(buffer)
console.log(audioData.sampleRate)
console.log(audioData.channelData[0])
console.log(audioData.channelData[1])
})
License
MIT