# Audio codecs setup / negotiation

## Overview

Audio codecs and fluctuations in network (jitter, packet loss) are 2 main factors that impact audio quality on a VoIP call. Although the possibilities to control quality of a network are usually limited, you can always configure codecs

👨‍🔧 For example one may select HD codecs only (like `G722`) on calls running through a particular AI Agent / Trunk preventing lower quality calls completely

👨‍🔧 Or they  may wish to sacrifice quality in a tradeoff for a reduction in audio bitrate (and thus consumed network bandwidth) by enabling `PCMA`, `PCMU`&#x20;

<figure><img src="/files/7CnofK9dtHuANo6meIZY" alt=""><figcaption><p>Turn on this setting when you want inbound codecs to be applied on both call legs</p></figcaption></figure>

{% embed url="<https://youtu.be/7CI6SVtM_xg>" %}

## But... how does that work on a call?

Codecs negotiation process may be a bit convoluted, so we provide examples to make it simpler!

This will help you in understanding how and when to set codecs on the inbound leg (A leg), outbound leg (B leg), and when to force them on both

## Codecs negotiation examples

When call gets set up there is 4 sets of codecs involved . This may seem excessive but let's have a look&#x20;

<figure><img src="/files/ERjrHFUI50eWx0hz7DM2" alt=""><figcaption></figcaption></figure>

*Calling party codecs (A)*

A caller will call with a set of codec supported by their device (*calling party codecs*)

*Called party codecs (B)*

A callee will have their own set of supported codecs (*called party codecs*)

*VoIP Number **outbound** codecs for calling party (VN-A)*

These codecs will negotiate media against *calling party codecs* on the A leg

*VoIP Number **inbound** codecs for called party (VN-B)*

These codecs will negotiate media against *called party codecs* on the B leg

2 sets (A, B) are controlled by the end points (caller / callee) and 2 (VN-A, VN-B) by [VoIP Number](https://docs.voipnumber.net/) in order to setup a media on both legs of a call. What you can always configure on [VoIP Number](https://docs.voipnumber.net/) is these 2 sets of codecs to be applied by [VoIP Number](https://docs.voipnumber.net/) on a caller and callee (VN-A, VN-B). If you control the endpoints then you can also configure codecs on them (A, B)

### Example 1. OFFNET call to Connection (OFFNET - ONNET)

Caller (PSTN or external SIP) dials in with (A) OPUS, G722 and PCMA

<figure><img src="/files/0dpIwBMaEripn0NmNLAA" alt=""><figcaption></figcaption></figure>

[VoIP Number](https://docs.voipnumber.net/) looks up the [Connection](/components/connection.md) and sees that it has inbound codecs configured to G722, PCMU, PCMA (VN-B). It sets these codecs on a B leg to [Connection](/components/connection.md) and rings it. [Connection](/components/connection.md) supports OPUS, G722, AMR-WB, PCMU, PCMA (B). G722 is the first codec present on both lists on the B leg (B, VN-B) and gets selected

Coming back to the A leg, because [Connection](/components/connection.md) did not enforce inbound codecs on a caller, a full set of codecs available on [VoIP Number](https://docs.voipnumber.net/) is offered to the caller (VN-A): OPUS, G722, AMR-WB, PCMU, PCMA. The first codec in common between A and VN-A is OPUS, so it gets selected

### Example 2. OFFNET call to Connection (OFFNET - ONNET) with codecs forced

Caller (PSTN or external SIP) dials in with (A) OPUS, G722 and PCMA

<figure><img src="/files/SVNbsIkzKOX9iX5m7Bk1" alt=""><figcaption></figcaption></figure>

[VoIP Number](https://docs.voipnumber.net/) looks up the [Connection](/components/connection.md) and sees that it has inbound codecs configured to G722, PCMU, PCMA (VN-B). It sets these codecs on a B leg to [Connection](/components/connection.md) and rings it. [Connection](/components/connection.md) supports OPUS, G722, AMR-WB, PCMU, PCMA (B). G722 is the first codec present on both lists on the B leg (B, VN-B) and gets selected

Coming back to the A leg, because [Connection](/components/connection.md) has `Force selected codecs on the caller` enabled - this same list (VN-B) is offered to the caller (VN-A): G722, PCMU, PCMA. The first codec in common between A and VN-A is G722, so it gets selected

### Example 3. Failed OFFNET call to Connection (OFFNET - ONNET) with codecs forced

Caller (PSTN or external SIP) dials in with (A) OPUS, G722 and PCMA

<figure><img src="/files/UVgmv48owPp8N83WtlRF" alt=""><figcaption></figcaption></figure>

[VoIP Number](https://docs.voipnumber.net/) looks up the [Connection](/components/connection.md) and sees that it has inbound codecs configured to G722, PCMU, PCMA (VN-B). It sets these codecs on a B leg to [Connection](/components/connection.md) and rings it. [Connection](/components/connection.md) supports OPUS, G722, AMR-WB, PCMU, PCMA (B). G722 is the first codec present on both lists on the B leg (B, VN-B) and gets selected

Coming back to the A leg, because [Connection](/components/connection.md) B has `Force selected codecs on the caller` enabled - this same list (VN-B) is offered to the caller (VN-A): G722, PCMU, PCMA. There is no codec in common between A (OPUS) and VN-A (G722, PCMU, PCMA) , so call is declined

This type of codec enforcement may be a deliberate strategy enforcing calls coming through a given [Trunk](/components/trunk.md) or [Connection](/components/connection.md) are always in high audio quality or with a low bitrate

### Example 4. ONNET call to Connection (ONNET - ONNET)

Connection A (SIP endpoint registered on [VoIP Number](https://docs.voipnumber.net/)) dials in with (A) OPUS, G722 and PCMA

<figure><img src="/files/eUgTPbJle5bkMoHEWktu" alt=""><figcaption></figcaption></figure>

[VoIP Number](https://docs.voipnumber.net/) looks up dialed [Connection](/components/connection.md) B and sees that it has inbound codecs configured to G722, PCMU, PCMA (VN-B). It sets these codecs on a B leg to [Connection](/components/connection.md) B and rings it. [Connection](/components/connection.md) B supports OPUS, G722, AMR-WB, PCMU, PCMA (B). G722 is the first codec present on both lists on the B leg (B, VN-B) and gets selected

Coming back to the A leg,  [VoIP Number](https://docs.voipnumber.net/) sees that [Connection](/components/connection.md) A has outbound codecs configured to OPUS, G722. Because [Connection](/components/connection.md) B did not enforce inbound codecs on a caller, this list of codecs is offered to the caller (VN-A): OPUS, G722. The first codec in common between A and VN-A is OPUS, so it gets selected

### Example 5. ONNET call to Connection (ONNET - ONNET) with codecs forced

Connection A (SIP endpoint registered on [VoIP Number](https://docs.voipnumber.net/)) dials in with (A) OPUS, G722 and PCMA

<figure><img src="/files/6Anp0WjbhDCChdbeIiO4" alt=""><figcaption></figcaption></figure>

[VoIP Number](https://docs.voipnumber.net/) looks up dialed [Connection](/components/connection.md) B and sees that it has inbound codecs configured to G722, PCMU, PCMA (VN-B). It sets these codecs on a B leg to [Connection](/components/connection.md) B and rings it. [Connection](/components/connection.md) B supports OPUS, G722, AMR-WB, PCMU, PCMA (B). G722 is the first codec present on both lists on the B leg (B, VN-B) and gets selected

Coming back to the A leg,  [VoIP Number](https://docs.voipnumber.net/) sees that [Connection](/components/connection.md) A has outbound codecs configured to OPUS, G722. Because [Connection](/components/connection.md) B has `Force selected codecs on the caller` enabled - this same list (VN-B) is offered to the caller (VN-A): G722, PCMU, PCMA. The first codec in common between A and VN-A is G722, so it gets selected

### Example 6. Call through a Trunk

With a [Trunk](/components/trunk.md) things are simpler. `TRUNK IN` codecs are offered on the A leg to caller (become VN-A list). `TRUNK OUT` codecs are offered on a B leg to called party (become VN-B list)

Caller dials in with (A) OPUS, G722 and PCMA

<figure><img src="/files/lJ0dhAiArb3Nrc7aJrJt" alt=""><figcaption></figcaption></figure>

[VoIP Number](https://docs.voipnumber.net/) looks up the [Trunk](/components/trunk.md) and sees that it has outbound codecs (`TRUNK OUT`) configured to G722, PCMU, PCMA (VN-B). It sets these codecs on a B leg to called party and rings it. Called party supports OPUS, G722, AMR-WB, PCMU, PCMA (B). G722 is the first codec present on both lists on the B leg (B, VN-B) and gets selected

Coming back to the A leg,  [VoIP Number](https://docs.voipnumber.net/) sees that [Trunk](/components/trunk.md) has inbound codecs (`TRUNK IN`) configured to G722, PCMU, PCMA. This list of codecs is offered to the caller (VN-A): G722, PCMU, PCMA. The first codec in common between A and VN-A is G722, so it gets selected

## How to

Open inbound / outbound settings of your [Connection](/components/connection.md) or [Trunk](/components/trunk.md)

You will find there a list of `Available` and `Selected` codecs

Move codecs between lists to build a list of selected codecs that is prioritised from the top to bottom (the top most entry on a list has highest priority). This means that when codecs are negotiated they are considered starting from the top most entry to the bottom

Only a codec that is present on your `Selected` list may be chosen on a call

Click on arrows to move codecs between `Available` and `Selected` lists

<figure><img src="/files/LqdUNU2iZKOVBEyZjZ1E" alt=""><figcaption></figcaption></figure>

Drag and drop them to rearrange position on a list

<figure><img src="/files/PdC8asPBWbCkPV6ZtwNl" alt=""><figcaption></figcaption></figure>

Save your settings once done

<figure><img src="/files/VvoxB3CWO9LS76vDruX2" alt=""><figcaption></figcaption></figure>

&#x20;✅  You have now configured codecs and defined acceptable audio quality and network bandwidth consumed


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.voipnumber.net/features/audio-codecs-setup-negotiation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
