Module g711

Module g711 

Source
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).