AVR Core provides comprehensive support for multiple audio codecs commonly used in VoIP telephony systems. The system automatically detects and handles different codec formats to ensure seamless integration with various PBX systems and telephony infrastructure.
- Standard: ITU-T G.711 μ-law
- Usage: Primary telephony codec in North America and Japan
- Bit Rate: 64 kbps
- Sample Rate: 8 kHz
- Compression: Logarithmic compression algorithm
- Standard: ITU-T G.711 A-law
- Usage: Primary telephony codec in Europe and most international systems
- Bit Rate: 64 kbps
- Sample Rate: 8 kHz
- Compression: Logarithmic compression algorithm
- Standard: Uncompressed audio format
- Usage: High-quality audio transmission, often used in modern VoIP systems
- Bit Rate: 128 kbps (16-bit) or 64 kbps (8-bit)
- Sample Rate: 8 kHz (standard telephony)
- Compression: None (uncompressed)
AVR Core implements intelligent codec detection that automatically identifies the incoming audio format without requiring manual configuration.
The system uses a statistical analysis approach to determine the codec:
- Audio Sample Analysis: Incoming audio packets are analyzed for characteristic patterns
- RMS Calculation: Root Mean Square values are calculated for both μ-law and A-law decoded samples
- Comparison Logic: The codec with higher RMS value is selected as the detected format
- Logging: The detected codec is logged for monitoring and debugging purposes
- Packet Reception: Audio packets are received from Asterisk via AudioSocket
- Codec Detection: Automatic detection occurs on the first few audio packets
- Decoding: Audio is decoded from the detected codec to linear PCM
- Processing: All internal processing uses 8kHz, 16-bit PCM format
- Forwarding: Processed audio is sent to ASR or STS services
- Audio Generation: TTS or STS services generate audio in PCM format
- Chunk Normalization: Audio is normalized into 320-byte chunks
- Encoding: Audio is encoded back to the appropriate codec format
- Transmission: Encoded audio is sent back to Asterisk
- Sample Rate: 8 kHz
- Bit Depth: 16-bit
- Channels: Mono
- Format: Linear PCM
- Chunk Size: 320 bytes (20ms at 8kHz)
case 'ulaw':
audioData = alawmulaw.mulaw.decode(audioData);
break;
case 'alaw':
audioData = alawmulaw.alaw.decode(audioData);
break;
No specific configuration is required for codec support as it's handled automatically. However, you can monitor codec detection through the logs:
Audio codec detected: ALAW
or
Audio codec detected: ULAW
or
Audio codec detected: SLIN
Correct Asterisk configuration is essential to ensure that AVR receives audio in a format it supports.
By default, AVR Core expects audio in signed linear PCM (slin16, 8kHz, 16-bit mono).
If Asterisk negotiates a codec that AVR does not support (for example, Opus), AVR will drop the call or log No audio received / unsupported format.
There are two primary ways to connect to AVR in your dialplan:
[demo]
exten => 5001,1,Answer()
same => n,Ringing()
same => n,Wait(1)
same => n,Set(UUID=${SHELL(uuidgen | tr -d '\n')})
same => n,AudioSocket(${UUID},127.0.0.1:5001)
same => n,Hangup()
- Pros: Asterisk automatically transcodes the inbound audio into slin16, ensuring AVR compatibility.
- Cons: Slightly higher CPU usage due to transcoding.
[demo]
exten => 5001,1,Answer()
same => n,Ringing()
same => n,Wait(1)
same => n,Set(UUID=${SHELL(uuidgen | tr -d '\n')})
same => n,Dial(AudioSocket/127.0.0.1:5001/${UUID})
same => n,Hangup()
- Pros: More scalable for large deployments (no local transcoding).
- Cons: AVR receives the native codec negotiated by the endpoint (e.g., Opus, A-law, μ-law). If the codec is not supported, AVR will immediately disconnect.
To avoid negotiation issues, configure your SIP endpoints in pjsip.conf to only allow codecs supported by AVR:
For A-law (Europe / International)
[endpoint-template](!)
type=endpoint
disallow=all
allow=alaw
...
For μ-law (North America / Japan)
[endpoint-template](!)
type=endpoint
disallow=all
allow=ulaw
...
For Linear PCM (best quality, higher bandwidth)
[endpoint-template](!)
type=endpoint
disallow=all
allow=slin16
This ensures that even when using Dial(AudioSocket/), AVR receives audio in a supported format.
You can check which codecs are being used with:
asterisk -rx "core show channel AudioSocket/127.0.0.1:5001-XXXX"
Example output:
State: Up
NativeFormats: (opus)
WriteFormat: opus
ReadFormat: slin
WriteTranscode: No
ReadTranscode: No
In this case, the endpoint negotiated Opus, but AVR requires slin16.
Result: AVR disconnects immediately with zero billsec.
If instead you see:
ReadFormat: slin
then AVR will work correctly.
- For testing and small setups → Use AudioSocket(). Asterisk handles transcoding automatically.
- For production deployments → Use Dial(AudioSocket/) but restrict endpoint codecs (alaw, ulaw, or slin16) to avoid negotiation problems.
- Always monitor logs: AVR will log the detected codec (Audio codec detected: ALAW/ULAW/SLIN) during the first packets of a call.
- Linear PCM: Lowest CPU usage (no conversion)
- A-law/μ-law: Moderate CPU usage (decoding required)
- Mixed Codecs: Higher CPU usage (frequent conversions)
- Buffer Size: 320 bytes per audio chunk
- Queue Management: Automatic chunk normalization
- Garbage Collection: Efficient buffer management
¶ Network Bandwidth
- μ-law/A-law: 64 kbps per call
- Linear PCM: 128 kbps per call
- Compression: Built-in codec compression reduces bandwidth
- Consistent Codec Usage: Use the same codec throughout the call session
- Quality vs. Bandwidth: Balance audio quality with network resources
- Monitoring: Regularly check codec detection logs
- Testing: Test with different codec configurations
- Fallback: Configure multiple codec options for compatibility
Planned improvements for audio codec support:
- Additional Codecs: Support for G.722, G.729, and other modern codecs
- Adaptive Quality: Dynamic codec selection based on network conditions
- Enhanced Detection: Machine learning-based codec detection
- Performance Optimization: Hardware-accelerated codec conversion