npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

riff-wave-reader

v0.3.7

Published

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

Downloads

70

Readme

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