What is μ-law (Mu-law) Audio Encoding?
The complete technical guide to G.711 μ-law for voice AI, telephony and VoIP — covering the compression formula, code implementations in Python, JavaScript and C, provider comparison, setup guides and troubleshooting.
What is μ-law (Mu-law)?
μ-law (mu-law) is a companding algorithm defined in ITU-T Recommendation G.711 that compresses 16-bit linear PCM audio into 8-bit logarithmic values. It is the standard audio codec for telephone networks in North America and Japan, and is widely used in VoIP, SIP and modern voice AI systems.
Why μ-law Matters in Voice AI
- Bandwidth efficiency — reduces audio data from 16-bit to 8-bit per sample (50% reduction)
- Telephony compatibility — standard format for PSTN networks and SIP trunks
- Real-time processing — near-zero latency encoding and decoding
- Voice quality — optimised for human speech frequencies (300–3,400 Hz)
- Universal support — every telephony platform, PBX and VoIP gateway supports it
Historical Context
Developed in the 1960s for digital telephony, μ-law became the standard companding algorithm for T1 carrier systems in North America. Today it remains essential in VoIP, SIP protocols and modern voice AI — including systems like the Team-Connect AI Receptionist that handle thousands of UK business calls daily.
How μ-law Works
The μ-law Compression Formula
Where x is the input sample (−1 ≤ x ≤ 1), μ is the compression parameter (255 for G.711), sgn(x) is the sign function, and ln is the natural logarithm.
Step-by-Step Process
Input Linear PCM
Start with a 16-bit linear PCM audio sample (range: −32,768 to +32,767)
Normalise Sample
Convert to normalised range (−1.0 to +1.0) by dividing by 32,768
Apply μ-law Compression
Use the formula with μ = 255 to compress the dynamic range logarithmically
Quantise to 8-bit
Map the compressed value to an 8-bit representation (0–255)
Add Sign Bit
Encode sign information in the MSB (most significant bit)
G.711 μ-law Technical Specifications
| Parameter | Value |
|---|---|
| Standard | ITU-T G.711 |
| Codec name | PCMU (Pulse Code Modulation μ-law) |
| Sample rate | 8,000 Hz |
| Bit depth | 8 bits per sample |
| Bit rate | 64 kbps |
| Compression parameter (μ) | 255 |
| Dynamic range | ~78 dB (≈13-bit equivalent) |
| Frequency range | 300–3,400 Hz |
| Frame size | Typically 20 ms (160 samples) |
| RTP payload type | 0 (RFC 3551) |
| SDP codec name | PCMU/8000 |
| Encoding latency | ~0.15 ms (near-zero) |
| CPU usage | Negligible (<1%) |
| Primary regions | North America, Japan |
Code Examples — Python, JavaScript and C
Python μ-law Encoder
Python μ-law Decoder
JavaScript Implementation
Optimised C Implementation
Implementation in Voice AI Systems
WebRTC Integration
SIP / SDP Configuration
Performance Optimisation Tips
- Lookup tables — pre-computed tables instead of runtime logarithms
- SIMD instructions — leverage vectorisation for batch processing
- Circular buffers — for streaming audio without allocation overhead
- Dedicated threads — separate encode/decode from application logic
- Pre-allocated memory — avoid malloc in the audio processing loop
μ-law Providers & Platforms
Major cloud and telephony platforms that support G.711 μ-law for voice AI and communications:
- Voice API with μ-law codec
- Real-time media streaming
- WebRTC integration
- Chime SDK Voice
- Kinesis Video Streams
- Transcribe real-time
- Speech-to-Text API
- Dialogflow CX
- Contact Centre AI
- Azure Comm Services
- Speech SDK
- Bot Framework
- Native G.711 codec
- Real-time transcoding
- WebRTC gateway
- Built-in μ-law codec
- SIP/IAX2 protocols
- ARI interface
- Native μ-law support
- AI voice recognition
- Real-time transcription
- Voice API
- WebSocket streaming
- Global carrier network
Complete μ-law Setup Guide
1. Environment Setup
2. Audio Input Configuration
3. Full μ-law Processor Class
4. Real-Time Processing Loop
Common Issues & Troubleshooting
1. Distorted or Poor Quality Audio
Causes: Incorrect sample rate conversion, clipping in input signal, wrong μ parameter, bit depth mismatch.
Fixes: Ensure input is normalised to [−1, 1]. Use anti-aliasing filter when downsampling. Verify μ = 255 for G.711. Check sign bit handling.
2. High Processing Latency
Causes: Large buffer sizes, inefficient encoding, memory allocation in audio loop.
Fixes: Use 160-sample buffers (20 ms). Implement lookup table encoding. Pre-allocate buffers. Use real-time thread priority.
3. Codec Compatibility Issues
Causes: Non-standard implementation, incorrect RTP payload, wrong SDP negotiation, endianness issues.
Fixes: Follow ITU-T G.711 exactly. Use RTP payload type 0. Implement proper SDP negotiation. Test with reference implementations.
Debugging Tools
μ-law vs Other Audio Codecs
| Codec | Bit Rate | Sample Rate | Quality | Latency | Use Case |
|---|---|---|---|---|---|
| μ-law (G.711) | 64 kbps | 8 kHz | Good | Very Low | Telephony, VoIP |
| A-law (G.711) | 64 kbps | 8 kHz | Good | Very Low | European telephony |
| G.722 | 64 kbps | 16 kHz | Very Good | Low | HD Voice |
| G.729 | 8 kbps | 8 kHz | Good | Medium | Low bandwidth VoIP |
| Opus | 6–510 kbps | 8–48 kHz | Excellent | Low | WebRTC, modern VoIP |
| PCM (16-bit) | 128 kbps | 8 kHz | Excellent | Very Low | Uncompressed |
When to Choose μ-law
Performance Benchmarks
μ-law Audio Encoding — 8 FAQs Answered
μ-law is a companding algorithm (G.711) that compresses 16-bit PCM to 8-bit logarithmic values. Standard codec for telephone networks in North America and Japan, widely used in VoIP and voice AI.
μ-law (PCMU) is North America/Japan standard. A-law (PCMA) is Europe/rest of world. Both compress 16-bit to 8-bit with slightly different curves. μ-law has marginally better SNR at low levels.
Near-zero latency, 50% bandwidth reduction, universal telephony compatibility, optimised for speech frequencies, and negligible CPU usage — ideal for real-time voice AI.
8 kHz sample rate, 8-bit samples, constant 64 kbps bitrate. Matches the 300–3,400 Hz bandwidth of traditional telephone networks.
Twilio, Amazon Connect, Google Cloud STT, Azure Communication Services, FreeSWITCH, Asterisk, Vonage and Team-Connect all support G.711 μ-law (PCMU).
Depends on the use case. μ-law has near-zero latency and universal PSTN/SIP compatibility. Opus has better quality and compression but slightly higher complexity — better for WebRTC-only systems.
RTP payload type 0, defined in RFC 3551. This is the default audio codec for most SIP and RTP implementations.
Check input normalisation (must be [−1, 1]), verify μ = 255, test with known reference signals, validate round-trip encode/decode, and check for sample rate mismatches between source and codec.