https://github.com/jbukuts/wav-parse
Isomorphic WAV file parser for JavaScript
https://github.com/jbukuts/wav-parse
isomorphic javascript js parser wav
Last synced: about 1 month ago
JSON representation
Isomorphic WAV file parser for JavaScript
- Host: GitHub
- URL: https://github.com/jbukuts/wav-parse
- Owner: jbukuts
- Created: 2025-01-26T16:16:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-16T09:27:54.000Z (over 1 year ago)
- Last Synced: 2025-07-05T06:40:10.860Z (12 months ago)
- Topics: isomorphic, javascript, js, parser, wav
- Language: TypeScript
- Homepage: https://jbukuts.github.io/wav-parse/
- Size: 11.3 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# wav-parse
This is a WAV file parser designed to extract header metadata and amplitude data from WAV files. It is written to support a multitude of WAV file encodings including:
- Little/big endian encoding
- WAV Extensible data
- A-law amplitude data
- ~Mu-law amplitude data~ (need to add reader function)
- Uncommon header chunks like `fact`/`peak`
> This package is designed to run in both browser and Node environments. Because of this `feross/buffer` is being used under the hood to facilitate this and allow me to extend the `Buffer` class with custom readers without affecting the native `Buffer` in Node.
## Examples
### Using Node
```ts
// start by getting the byte data of a given WAV file
const buffer = fs.readFileSync('./test.wav')
// read just the header info
const { header, offset } = parseHead(buffer)
// offset represents the byte-size of the header.
// or read the header and all amplitude data
const {
chunkId,
chunkSz,
type,
data,
fmt,
fact,
peak
amplitudeData,
} = readFile(buffer)
// amplitudeData will be a TypedArray
```
### In the browser
```ts
// get a File object somehow
const readFileAsArrayBuffer = async (f: File): Promise => {
const reader = new FileReader();
return new Promise((res) => {
reader.onload = (event) => {
const result = event.target?.result as ArrayBuffer;
res(result);
};
reader.readAsArrayBuffer(f);
});
};
// turn file ref into ArrayBuffer of byte data
const arrBuffer = await readFileAsArrayBuffer(file)
// read the header info
const { header, offset } = parseHead(arrBuffer)
```