You pick one codec per attach and the bridge does the rest. Whatever the carrier negotiated on the wire — µ-law from a North American trunk, A-law from a European one, Opus from a browser — the bridge transcodes it to the codec your code asked for, and transcodes your replies back. You never run media tooling in your own process, and you never have to match the carrier’s format to read the audio. This page is the decision guide: the four codecs TeleQuick Voice exposes, when each is the right call, and the two cases where you skip transcoding entirely for a zero-cost passthrough.

The four codecs

Every SDK surfaces the same AudioCodec type. Set it when you attach an audio bridge or bind an agent:
CodecWire formatRateWhen to use it
opusOpus (48 kHz mono)48 kHzDefault. Browser/app legs; best quality-per-bit.
pcm16Raw 16-bit PCM LE8 kHz¹Feeding a realtime AI model that wants uncompressed input.
g711_ulawG.711 PCMU (PT 0)8 kHzPSTN-direct, no transcode. µ-law — North America and Japan.
g711_alawG.711 PCMA (PT 8)8 kHzPSTN-direct, no transcode. A-law — most of the rest of the world.
¹ pcm16 frames are 8 kHz mono on the call bus by default; set sampleRate to resample. See Audio shape.
import { Voice } from "@telequick/sdk/voice";

const voice = new Voice({ apiKey: process.env.TELEQUICK_API_KEY! });

// Attach the server side of a call, asking for PCM16 to feed a model.
const bridge = await voice.audioBridge.attach(sid, { codec: "pcm16" });
bridge.onUplink((tsUs, pcm) => model.push(pcm));   // caller audio, decoded for you
Voice is audio-only — there are no video codecs on this path. If you don’t set a codec, you get opus.

Choosing a codec

Work from the consumer of the audio, not the carrier — the carrier leg is the bridge’s problem, not yours:
1

Talking to a browser or app? Use opus.

Browser softphones capture and encode Opus natively (the encoder is borrowed straight from the browser’s audio pipeline). Keeping the leg on opus end-to-end means no re-encode and the best quality for the bitrate. This is the default for a reason.
2

Feeding a realtime AI model? Use pcm16.

Most speech-to-speech and ASR models want uncompressed PCM on their input. Ask for pcm16 and the bridge hands your code decoded 16-bit samples with no codec in the middle — the same raw format the agent runtime uses internally.
3

Bridging straight to a PSTN trunk? Match the trunk's G.711.

If you’re relaying a call leg to a SIP/PSTN trunk and don’t need to inspect or transform the audio, ask for the trunk’s own G.711 variant — g711_ulaw for North America and Japan, g711_alaw for the rest of the world. The frames pass through untouched (see passthrough).
µ-law vs A-law is a regional wire convention, not a quality choice. North American and Japanese carriers use µ-law (PCMU, payload type 0); nearly everyone else uses A-law (PCMA, payload type 8). Both are 8 kHz 8-bit companded G.711 with effectively identical fidelity. Pick the one your carrier negotiates — if you get it wrong you’ll hear distortion, and the bridge will transcode between the two anyway when two G.711 legs of different flavours meet.

Transcoding at the bridge

Carrier legs almost always arrive as G.711 at 8 kHz (PCMU or PCMA); browser legs arrive as Opus at 48 kHz. The bridge sits between the wire and your code and converts in both directions, decoding to the runtime’s internal PCM representation and re-encoding to whatever each side needs:
 CALLER LEG                         BRIDGE                      YOUR CODE
 ┌──────────────┐                                             ┌──────────────┐
 │ PSTN G.711   │ ──decode──▶  8 kHz PCM16 (agent bus)  ──────▶│ codec: pcm16 │
 │ µ-law/A-law  │ ◀─encode──   ◀────── your reply PCM ─────────│  (or opus)   │
 └──────────────┘                                             └──────────────┘
 ┌──────────────┐                                             
 │ Browser Opus │ ──decode/resample 48↔8 kHz──▶  PCM16  ──────▶ same bus
 └──────────────┘                                             
Two consequences worth knowing:
  • The runtime bus is 8 kHz PCM16 end-to-end. A 20 ms tick is 160 samples at 8 kHz. That’s the fidelity ceiling for anything routed through the agent path — telephone-band audio, which is exactly what PSTN delivers and what speech models are trained on.
  • Opus keeps a 48 kHz RTP clock even though the audio is narrowband. The Opus rtpmap stays opus/48000/2 and each 20 ms frame advances the timestamp by 960, per the codec’s spec, while the encoder’s internal rate is driven to narrowband to match the bus. You don’t manage any of this — it’s the fix that makes browser Opus play back clean — but it’s why you’ll see 48000 in an SDP even for an 8 kHz call.

Passthrough fast paths (zero transcode)

Transcoding is cheap, but the fastest audio is audio you never touch. Two paths skip the codec entirely:
1

G.711 in, same G.711 trunk out.

When you bridge a PSTN leg to another PSTN/SIP trunk of the same G.711 flavour and ask for that flavour, the bridge relays the frames verbatim — no decode, no re-encode. This is the norm for straight call-forwarding and carrier hand-off.
2

External µ-law WebSocket audio to a µ-law trunk.

Migrating from a Twilio Media Streams–style source? Its 8 kHz µ-law WebSocket frames map straight onto a PCMU SIP trunk with zero transcode — the payloads are already in the trunk’s format. See Migrate from Twilio for the wiring.
Passthrough only holds when both ends agree on the codec. Ask for pcm16 or opus on a G.711 leg and you opt into a transcode — which is fine and often what you want (you can’t feed a model raw companded G.711), just not free. If two G.711 legs disagree — one µ-law, one A-law — the bridge transcodes between them automatically rather than sending garbled audio.

Audio shape: sampleRate, channels, frameMs

Codec choice sets the format; three more knobs set the shape. All have sensible defaults, so you usually set only codec:
codec
"opus" | "pcm16" | "g711_ulaw" | "g711_alaw"
default:"opus"
The wire format for this leg, per the table above.
sampleRate
number
default:"48000"
Samples per second. opus runs at 48000; G.711 is fixed at 8000. For pcm16, set this to the rate your model wants (e.g. 16000 or 24000) and the bridge resamples for you — the stateful resampler avoids the “chipmunk” artefacts of a naive double-resample.
channels
number
default:"1"
Voice is mono. Recordings mix the two legs into stereo (caller left, agent right) downstream — that’s a recording concern, not a codec one.
frameMs
number
default:"20"
Milliseconds of audio per frame/object. 20 ms is the RTP and Opus standard (160 samples at 8 kHz, 960 at 48 kHz) and what every pacer and jitter buffer on the path assumes. Change it only if a downstream consumer demands it.

Sessions, calls, tracks & streams

Where the codec’s capability tag (voice/opus, voice/pcm16) fits the track model.

SIP trunking

How carrier legs negotiate G.711 on the wire before the bridge sees them.

Browser audio capture

The Opus path: borrowing the browser’s encoder onto QUIC/MoQT.

Migrate from Twilio

The µ-law WebSocket → PCMU trunk passthrough on-ramp.