Expand description
G.711 μ-law and A-law codecs — the audio dialect of the public phone network.
Every PSTN leg (Twilio Media Streams, SIP trunks, carrier gateways) delivers 8 kHz audio in one of these two companding formats: μ-law in North America and Japan, A-law nearly everywhere else. Both pack a 14/13-bit linear sample into one logarithmically-companded byte.
The functions here are pure, allocation-explicit, and implement ITU-T
G.711 directly (bit manipulation, no tables to drift): encode from mono
PCM16, decode back to mono PCM16. Pair them with
resample to move between the 8 kHz telephone
rate and the Live API’s 16 kHz-in / 24 kHz-out contract.
Functions§
- alaw_
to_ linear - Decode one A-law byte to a linear PCM16 sample (ITU-T G.711).
- decode_
alaw - Decode an A-law byte stream to mono PCM16 samples.
- decode_
ulaw - Decode a μ-law byte stream to mono PCM16 samples.
- encode_
alaw - Encode mono PCM16 samples as an A-law byte stream.
- encode_
ulaw - Encode mono PCM16 samples as a μ-law byte stream.
- linear_
to_ alaw - Encode one linear PCM16 sample as an A-law byte (ITU-T G.711).
- linear_
to_ ulaw - Encode one linear PCM16 sample as a μ-law byte (ITU-T G.711).
- ulaw_
to_ linear - Decode one μ-law byte to a linear PCM16 sample (ITU-T G.711).