Read 8 bit WAVE files with PCM datain the RIFF file format
Find a file
2019-09-14 00:17:19 -04:00
.github/ISSUE_TEMPLATE Update issue templates 2019-05-09 09:33:45 -04:00
docs chore: build 2019-09-14 00:13:16 -04:00
samples chore: add 24 bit sample 2019-09-14 00:08:26 -04:00
scripts chore: disable console nag 2019-09-01 20:58:17 -05:00
spec chore: test reading 24 bit files 2019-09-14 00:13:05 -04:00
src chore: destructure format 2019-09-14 00:12:32 -04:00
.babelrc chore: upgrade babel 2019-05-05 21:40:33 -04:00
.commitlintrc.js chore: de-echo (#24) 2019-05-03 22:52:37 -04:00
.eslintrc configure linting 2019-05-02 00:04:37 -04:00
.gitignore chore: ignore folder view 2019-05-10 09:46:10 -04:00
.huskyrc chore: de-echo (#24) 2019-05-03 22:52:37 -04:00
.travis.yml #17 reduce build targets 2019-05-03 20:15:58 -04:00
CHANGELOG.md feat: 🔖Release v0.3.7 2019-09-14 00:16:57 -04:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md 2019-05-09 09:45:05 -04:00
CONTRIBUTING.md Create CONTRIBUTING.md 2019-05-09 09:43:30 -04:00
LICENSE.md Initial commit 2019-05-01 21:03:34 -04:00
package-lock.json feat: 🔖Release v0.3.7 2019-09-14 00:16:57 -04:00
package.json feat: 🔖Release v0.3.7 2019-09-14 00:16:57 -04:00
PULL_REQUEST_TEMPLATE.md chore: rename pr template 2019-05-09 21:28:07 -04:00
README.md chore: pretty 2019-09-01 21:04:25 -05:00
webpack.config.js chore: pretty 2019-09-01 20:59:16 -05:00

Riff Wave Reader

Build Status npm version install size

This library reads the data within RIFF file with it's contents formatted as a WAVE file containing PCM data.

Live Demo on GitHub Example Waveform

Installation

This npm package is available as riff-wave-reader

From your terminal, install with the following command.

npm install riff-wave-reader --save

How to use

Node

import Reader from "riff-wave-reader/reader";
let reader;
const channel = 0;
const index = 0;

// from array
const data =
  "52 49 46 46 d5 10 00 00 57 41 56 45 66 6d 74 20 " +
  "10 00 00 00 01 00 01 00 40 1f 00 00 40 1f 00 00 " +
  "01 00 08 00 64 61 74 61 b1 10 00 00 7f";
const array = data.split(" ").map(v => parseInt(v, 16));
reader = new RiffWaveReader(array);

// To handle large files without loading them completely into memory
// from wrapped file, buffer, array, and array buffers
reader = new RiffWaveReader(new Reader("./samples/hello.wav"));
reader = new RiffWaveReader(new Reader(Buffer.from(array)));
reader = new RiffWaveReader(new Reader(array));
reader = new RiffWaveReader(new ArrayBuffer(array));

// Read header chunks
reader.readChunks().then(chunks => {
  console.log(chunks);
});
reader.readSample(channel, index).then(sample => console.log(sample));
// 127

The chunks would be written out as:

{
  "riff": {
    "tag": "RIFF",
    "size": 4309,
    "format": "WAVE"
  },
  "format": {
    "id": "fmt ",
    "size": 16,
    "type": 1,
    "channels": 1,
    "sampleRate": 8000,
    "byteRate": 8000,
    "blockAlignment": 1,
    "bitsPerSample": 8,
    "typeName": "PCM",
    "sampleSize": 1
  },
  "data": {
    "id": "data",
    "size": 4273,
    "start": 44,
    "sampleCount": 4265,
    "duration": 0.533125
  }
}

Web Browser

<script src="riff-wave-reader.js" type="text/javascript"></script>
<input type="file" change="changeFile(this.files)" />
<script type="text/javascript">
  function changeFile(files) {
    const fileReader = new FileReader();
    fileReader.onload = function(e) {
      var RiffWaveReader = window["riff-wave-reader"].RiffWaveReader;
      var riffReader = new RiffWaveReader(e.target.result);
      riffReader.readChunks().then(function(chunks) {
        console.log(chunks);
      });
    };
    fileReader.readAsArrayBuffer(files[0]);
  }
</script>

Modifications

Building

Building is done via webpack as a universal module definition (UMD) library.

From terminal

npm run build
  1. Creates a script in development mode under /docs/dist/riff-wave-reader.js
  2. Creates a script in production mode under /lib/dist/riff-wave-reader.js along with a sourcemap file

Local Testing

From terminal

npm run start

Your web browser will open http://localhost:3000/docs/index.html