1.0.0 • Published 1 month ago
@silyze/async-audio-format-wav v1.0.0
Async Audio Format WAV
@silyze/async-audio-format-wav
provides a WAV (RIFF) wrapper around raw 16‑bit little‑endian PCM for use with @silyze/async-audio-stream
.
- Adds a minimal 44‑byte WAV header in‑place as the stream starts.
- Keeps the rest of the data untouched & streaming‑friendly (no file‑length seek).
- Perfect when you need a quick WAV stream for players, APIs, or debugging.
Install
npm install @silyze/async-audio-format-wav
No external dependencies — everything is pure TypeScript.
Usage
import WavFormat from "@silyze/async-audio-format-wav";
// Create a WAV format for 16 kHz mono PCM:
const format = new WavFormat(16000);
console.log(format.name); // "wav-pcm"
console.log(format.pcmSampleRate); // 16000
// Encode a raw PCM AsyncReadStream<Buffer> to WAV on‑the‑fly:
const wavStream = format.encode(pcmStream);
Available Format
Class | Container | Codec | Channels | Notes |
---|---|---|---|---|
WavFormat | WAV | PCM‑16‑LE | Mono | decode() throws (not supported) |
API
class WavFormat extends AudioFormat {
constructor(sampleRate: number);
readonly name: string; // "wav-pcm"
readonly pcmSampleRate: number;
/** Adds the WAV header then streams the original PCM bytes. */
encode(input: AsyncReadStream<Buffer>): AsyncReadStream<Buffer>;
/** Not implemented — throws an Error. */
decode(_: AsyncReadStream<Buffer>): never;
}
Why no decode()
?
In many live/streaming scenarios you already have raw PCM from an upstream capture or decode stage.@silyze/async-audio-format-wav
focuses on wrapping that data for consumer compatibility.
If you need WAV → PCM, use @silyze/async-audio-ffmpeg
with a suitable format instead.
1.0.0
1 month ago