Choosing between opus vs g711 for a voice AI application is a critical architectural decision. The right audio codec ensures your system is efficient, responsive, and compatible with your users' devices. The wrong choice can lead to high bandwidth costs, poor audio quality, and frustrating delays. This guide provides a practical comparison to help you choose wisely.

Key takeaways

  • G.711 is for compatibility. It is the universal standard for digital telephony. Use it when your voice AI needs to connect with the Public Switched Telephone Network (PSTN) or legacy SIP systems.
  • Opus is for the internet. It is a modern, flexible codec ideal for applications like WebRTC. Opus delivers higher quality audio at lower bitrates and adapts gracefully to changing network conditions.
  • Bandwidth is more than the bitrate. A codec's bitrate only describes the audio payload. You must also account for the significant overhead from network protocol headers when planning system capacity.
  • Latency is a system-wide problem. The codec itself is only one small source of delay. Total conversational latency depends more on network conditions, audio buffers, and your AI's processing time.
  • The call path dictates the choice. If your voice agent connects to the phone network, G.711 is often the simplest choice to avoid transcoding. If your agent runs entirely over the internet (e.g., browser to server), Opus is superior.

What are audio codecs and why do they matter for voice AI?

An audio codec is a software or hardware component that encodes and decodes digital audio for transmission or storage. The name "codec" is a blend of "coder" and "decoder." Its job is to make large audio data streams small enough to send efficiently over a network like the internet or a phone line.

For a voice AI system, the codec choice directly impacts three critical factors: audio quality, network bandwidth, and latency. The quality of the audio fed into a speech recognition engine affects its accuracy. The bandwidth determines the operational cost and the number of concurrent calls a server can handle. Latency affects how responsive and natural the conversation feels. These factors are in a constant trade-off, and the right codec helps strike the best balance for your specific voice AI agent architecture.

How G.711 and Opus work

G.711 and Opus represent two different eras of audio technology. G.711 is a simple, robust standard from the world of telephony, while Opus is a flexible, intelligent codec built for the modern internet.

G.711: The telephony standard

Standardized in 1988, G.711 was designed to digitize voice for telephone networks. It works in a straightforward, predictable way:

  1. Sampling: Audio is sampled 8,000 times per second. This captures frequencies up to about 4 kHz, which covers the essential range of the human voice for intelligibility. This is called "narrowband" audio.
  2. Companding: Instead of complex compression, G.711 uses a technique called companding. It represents each audio sample using just 8 bits, but does so on a logarithmic scale. This gives more precision to quiet sounds (where human hearing is more sensitive) and less precision to loud sounds.
  3. Bitrate: The result is a simple, constant stream of data at 64,000 bits per second (64 kbit/s) (ITU-T G.711 Recommendation).
  4. Variants: There are two main G.711 variants: PCMU (μ-law), used in North America and Japan, and PCMA (A-law), used nearly everywhere else (RFC 3551). They are not directly compatible, so systems must agree on which one to use.

G.711's simplicity and long history make it universally supported in the world of telephony (Wikipedia).

Opus: The internet chameleon

Opus was standardized by the Internet Engineering Task Force (IETF) in 2012 specifically for interactive internet audio (RFC 6716). It is a much more advanced and flexible codec.

  1. Hybrid Design: Opus combines two different algorithms. For speech, it uses SILK (the engine behind Skype). For general audio like music, it uses a low-delay algorithm called CELT. It can seamlessly switch between them or even combine them.
  2. Flexibility: Unlike G.711's fixed settings, nearly everything in Opus is configurable. It supports sampling rates from 8 kHz (narrowband) all the way to 48 kHz (fullband, which covers the generally accepted range of human hearing).
  3. Variable Bitrate (VBR): Opus can dynamically adjust its bitrate from 6 kbit/s up to 510 kbit/s to match network conditions (RFC 6716). If the network is congested, it can reduce its bitrate to avoid dropping packets. When the network is clear, it can increase the bitrate for higher quality.
  4. Packet Loss Concealment: Opus has sophisticated built-in mechanisms to handle lost network packets. It can intelligently guess what the missing audio might have been, making dropouts less noticeable.

This adaptability makes Opus highly resilient and efficient for use over unpredictable networks like public Wi-Fi or mobile data.

Bandwidth: Why 64 kbit/s is not 64 kbit/s

A common mistake is to assume a codec's bitrate equals the total network bandwidth used. In reality, the codec's data is just the "payload" inside a larger network packet. You must also account for the headers used by transport protocols. Let's calculate the true bandwidth for a typical G.711 call.

For this example, we will assume a standard configuration where audio is collected into 20-millisecond (ms) frames. This means 50 packets are sent every second.

  1. Calculate Payload Size:

    • Codec Bitrate: 64,000 bits per second (bps)
    • Frame Duration: 0.020 seconds
    • Payload per Packet: 64,000 bps * 0.020 s = 1,280 bits
    • Payload in Bytes: 1,280 bits / 8 bits per byte = 160 bytes
  2. Add Header Sizes: The audio payload is wrapped in several protocol layers for transport. These header sizes are defined by internet standards (RFC 3551).

    • RTP (Real-time Transport Protocol): 12 bytes
    • UDP (User Datagram Protocol): 8 bytes
    • IPv4 (Internet Protocol): 20 bytes
    • Total Header Size: 12 + 8 + 20 = 40 bytes
  3. Calculate Total Packet Size:

    • Total Packet Size: 160 bytes (Payload) + 40 bytes (Headers) = 200 bytes
  4. Calculate Final Bandwidth:

    • Packets per Second: 50
    • Total Bandwidth: 200 bytes/packet * 50 packets/sec * 8 bits/byte = 80,000 bps
    • Final Bandwidth: 80 kbit/s

In this typical scenario, the network overhead adds 16 kbit/s, a 25% increase over the codec bitrate alone. In contrast, an Opus stream configured for high-quality voice at 32 kbit/s would use a total bandwidth of only 48 kbit/s under the same conditions, demonstrating its efficiency.

Opus vs. G.711: A detailed comparison

This table summarizes the key differences between the two codecs.

Feature G.711 Opus
Standardization ITU-T (Telephony) IETF (Internet)
Audio Bandwidth Narrowband (~3.4 kHz) Narrowband to Fullband (up to 20+ kHz)
Sampling Rate 8 kHz (fixed) 8, 12, 16, 24, 48 kHz (configurable)
Bitrate 64 kbit/s (fixed) Variable (typically 6–510 kbit/s)
Algorithmic Latency Very Low (< 1 ms) Low & Configurable (minimum 5 ms lookahead + frame size) (RFC 6716)
Network Adaptability None Excellent (Variable Bitrate, FEC)
Packet Loss Handling Basic concealment (if implemented by receiver) Advanced built-in concealment & optional Forward Error Correction (FEC)
Primary Use Case PSTN, Legacy SIP/PBX WebRTC, Modern VoIP, Internet Audio
Interoperability Universal in telephony Universal in WebRTC, support varies in SIP/PBX

Which codec has lower latency in practice?

While G.711 has a lower internal processing delay, it does not guarantee a lower end-to-end conversational latency. Total latency is what a user actually feels, and it is a sum of multiple delays throughout the audio pipeline. The codec's contribution is often one of the smallest.

Here are the key components of voice agent latency:

  • Algorithmic Delay: The time a codec needs to process the audio. For G.711, this is almost zero (<1 ms) (ITU-T G.711 Recommendation). For Opus, it is slightly higher due to its need to "look ahead" at the audio, with a minimum of 5 ms plus the frame size (RFC 6716).
  • Packetization Delay: The time spent collecting audio to fill a packet. If you use 20 ms audio frames, you add 20 ms of delay before the packet can even be sent. This is often the largest source of controllable latency.
  • Network Transit Delay: The time it takes for the packet to travel across the network. This is the "ping time" between the user and your servers.
  • Jitter Buffer Delay: The receiver holds packets briefly in a buffer to handle network jitter (variations in packet arrival time). This is often the largest and most variable source of latency, easily adding 30-200 ms.
  • AI Processing Delay: The time your speech recognition, language model, and text-to-speech systems take to generate a response.

In a real system, a large jitter buffer or slow AI processing will have a much bigger impact on responsiveness than the difference between Opus and G.711's algorithmic delay.

How do codecs affect interoperability and transcoding?

Interoperability is G.711's greatest strength. Any device built for telephony in the last 30 years—from an office PBX to a global carrier network—is guaranteed to support it. This makes it the "lingua franca" for connecting a voice AI to the traditional phone system via SIP trunking.

Opus, while dominant in the web world via WebRTC, has less consistent support in legacy telephony hardware. For more on web-based audio, see this helpful guide to web audio codecs.

This leads to a critical process called transcoding. Transcoding is the process of decoding audio from one codec and re-encoding it into another. This happens whenever two systems that don't share a common codec need to communicate.

For example, if a user calls your voice agent from their mobile phone, the audio might travel over the PSTN as G.711. If your AI platform is built to use Opus internally, a gateway must transcode the G.711 stream into an Opus stream. This process adds latency, consumes CPU resources, and can slightly degrade audio quality.

Therefore, a key design principle is to avoid transcoding whenever possible. If your voice agent primarily receives calls from the phone network, accepting G.711 directly is often the most efficient and robust solution.

Common Pitfalls to Avoid

  • Assuming Opus "Just Works": Before choosing Opus, you must verify that every component in your call path—gateways, SIP trunks, browsers, and servers—fully supports it. Mismatched configurations can lead to failed calls or silent audio.
  • Ignoring ASR Tuning: Feeding narrowband G.711 audio into a speech recognition model that was trained exclusively on wideband audio can significantly increase word error rates. Always test your ASR with audio that matches your production environment.
  • Overestimating Packet Loss Concealment (PLC): While Opus has excellent PLC, its purpose is to make short audio gaps less jarring, not to perfectly reconstruct lost words. High packet loss will still result in degraded speech intelligibility.
  • Confusing Sample Rate with Quality: Setting Opus to a high sample rate like 48 kHz doesn't magically add high-frequency information that wasn't there to begin with. If the original audio source is a narrowband telephone call, the output will still be narrowband.

What to learn next

Sources and further reading