@silyze/async-audio-format-ulaw
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Async Audio Format µ‑law (G.711)

@silyze/async-audio-format-ulaw adds µ‑law (G.711) support to the
@silyze/async-audio-stream
ecosystem.
It performs in‑memory conversion between 8‑bit µ‑law and 16‑bit little‑endian PCM,
streaming‑friendly and fully async.


Install

npm install @silyze/async-audio-format-ulaw

Depends on alawmulaw for the actual codec maths (bundled as a normal dependency).


Usage

import ULawFormat from "@silyze/async-audio-format-ulaw";

// Typically, µ‑law is 8 kHz mono:
const format = new ULawFormat(8000);

// Encode raw PCM → µ‑law:
const ulawStream = format.encode(pcmStream);

// Decode µ‑law → raw PCM:
const pcmStream = format.decode(ulawStream);

Available Format

Class Container Codec Channels Notes
ULawFormat Raw bytes µ‑law Mono Bidirectional encode / decode streams

API

class ULawFormat extends AudioFormat {
  constructor(sampleRate: number); // e.g. 8000

  readonly name: string; // "ulaw"
  readonly pcmSampleRate: number; // constructor value

  /** PCM‑16‑LE → µ‑law (8‑bit) */
  encode(input: AsyncReadStream<Buffer>): AsyncReadStream<Buffer>;

  /** µ‑law (8‑bit) → PCM‑16‑LE */
  decode(input: AsyncReadStream<Buffer>): AsyncReadStream<Buffer>;
}

Both encode() and decode() are implemented with the
alawmulaw library and run inside
stream map() transforms, so they start processing as soon as data arrives.


Implementation Notes

  • Sample‑rate‑agnostic – although typical µ‑law telephony audio is 8 kHz, you
    may instantiate ULawFormat with any sample rate if your pipeline uses
    different values.
  • Lossy – µ‑law is a companded 8‑bit representation; converting back to PCM
    cannot fully restore the original 16‑bit dynamic range.

Readme

Keywords

none

Package Sidebar

Install

npm i @silyze/async-audio-format-ulaw

Weekly Downloads

8

Version

1.0.1

License

MIT

Unpacked Size

43.7 kB

Total Files

13

Last publish

Collaborators

  • simeonmarkoski
  • mojsoski