rapid-hamburger-23505
12/09/2025, 10:46 PMgithub.com/livekit/server-sdk-go/v2
• SIP Provider: Plivo (Outbound Trunk).
• Flow: Worker connects to room -> Waits for SIP participant -> Publishes Audio Track -> Sends TTS audio.
The Issue: The call connects successfully, and the SIP participant (phone) answers. The worker receives audio from the phone perfectly. The worker also sends audio (logs show frames being encoded and sent), but the phone hears absolute silence.
What I've Tried:
1. Opus Codec: Standard webrtc.MimeTypeOpus (48kHz). Result: Silence.
2. G.711 PCMA: Switched to manual G.711 A-law encoding (8kHz, 20ms frames) using webrtc.MimeTypePCMA. Result: Silence.
3. Network: Forced ICETransportPolicyRelay to rule out NAT/Firewall issues. Connection is stable (ICE connected).
Logs (Worker Side): It looks like the track is published and data is flowing:
"message":"[AUDIO] publishing PCMA audio track (G.711 A-law)"
"message":"published track", "name"="agent-audio", "source"="MICROPHONE"
"message":"[AUDIO] PCMA frame encoded", "pcma_bytes":160, "payload_preview":"d52aaad5..."
"message":"[AUDIO] pacing progress", "frames_sent":100
"message":"[AUDIO] pacing progress", "frames_sent":200
Code Snippet (Audio Publishing): I'm using TrackLocalStaticSample and writing 20ms frames manually.
// Publishing the track
track, err := webrtc.NewTrackLocalStaticSample(
webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypePCMA},
"agent-audio",
"agent-stream",
)
_, err = room.LocalParticipant.PublishTrack(track, &lksdk.TrackPublicationOptions{
Name: "agent-audio",
})
// Writing Audio (Pacing Loop)
// Sending 160-byte frames every 20ms (8kHz A-law)
sample := media.Sample{
Data: audioFrame,
Duration: 20 * time.Millisecond,
}
err := track.WriteSample(sample)
SIP Config (Plivo):
{
"provider": "PLIVO",
"transport": "tcp",
"codecs": ["PCMA", "PCMU", "G722"] // (Assumed defaults)
}
Questions:
1. Are there known issues with TrackLocalStaticSample for SIP outbound?
2. Does the SIP Gateway require specific RTP header extensions or StreamIDs to recognize the audio?
3. Could this be an encryption mismatch (SRTP) even if the connection is established?
Any help debugging this would be amazing. Thanks!tall-airline-16756
12/09/2025, 10:46 PMtall-airline-16756
12/09/2025, 10:46 PMwebrtc.MimeTypeOpus) at 48 kHz and let the gateway transcode to G.711. Manual G.711 tends to bypass LiveKit’s pipeline and commonly fails with SIP gateways.
1. Confirm subscription events
◦ Log track subscription events on the room to verify the SIP participant/gateway actually subscribed to your published track.
1. Verify RTP on the wire
◦ Capture RTP with Wireshark on the worker:
▪︎ Confirm RTP packets reach the SIP gateway IP.
▪︎ Check payload type, clock rate, SSRC, seq numbers.
▪︎ If packets are sent but the gateway reports no media, gateway side is the issue.
1. Check SDP/payload mapping
◦ Inspect the SDP offered/answered for the call and ensure PCMA payload type and clock rate are present and mapped as the gateway expects (PCMA is static PT=8, clock 8kHz).
1. Test trunk with known-good audio
◦ Use LiveKit’s outbound call test options (or play a dialtone/sine file via the CLI/room setup) to validate the Plivo trunk can receive and play audio from LiveKit.
1. Try file-based/simple source
◦ Replace TTS with a simple PCM/Opus file played via the track to rule out TTS framing/encoding timing issues.
1. Avoid manual G.711 samples if possible
◦ Your 160-byte / 20ms frames are correct size, but manually writing G.711 samples bypasses LiveKit’s handling and often fails for SIP outbound. Prefer Opus + gateway transcoding.
What to look for in logs
• On LiveKit: track published, track subscribed by SIP participant, no subscription events means gateway ignored it.
• On Plivo: “no media received”, codec mismatch, or media timeouts.
If you want, next I can:
• Show a minimal Go snippet that publishes Opus and logs subscription events.
• Help interpret a packet capture or your SDP (paste the SDP offer/answer and I’ll point out suspicious fields). Sources: SIP overview | LiveKit docs | Create and configure a Plivo SIP trunk | LiveKit docs | sip | livekit/livekit_composite | DeepWiki | Making outbound calls | LiveKit docs | HD voice for SIP | LiveKit docsrapid-hamburger-23505
12/09/2025, 10:50 PMrapid-hamburger-23505
12/09/2025, 10:51 PMtall-airline-16756
12/09/2025, 10:52 PMpackage main
import (
"log"
"math"
"os"
"os/signal"
"time"
lksdk "github.com/livekit/server-sdk-go/v2"
"github.com/livekit/protocol/livekit"
"github.com/livekit/server-sdk-go/v2/pkg/tokens"
)
func main() {
apiKey := "YOUR_API_KEY"
apiSecret := "YOUR_API_SECRET"
roomName := "test-room"
identity := "go-agent"
// create short-lived token
grant := &tokens.VideoGrant{
Room: roomName,
RoomJoin: true,
CanPublish: true,
CanSubscribe: true,
}
token, err := tokens.NewAccessToken(apiKey, apiSecret).WithVideoGrant(grant).ToJWT()
if err != nil {
log.Fatal(err)
}
// join room
room, err := lksdk.ConnectToRoom("wss://your-livekit-host", &lksdk.ConnectInfo{
APIKey: apiKey,
APISecret: apiSecret,
RoomName: roomName,
ParticipantIdentity: identity,
Token: token,
})
if err != nil {
log.Fatal(err)
}
defer room.Disconnect()
// callbacks: participant / track events
room.OnParticipantConnected(func(p *lksdk.RemoteParticipant) {
log.Printf("participant connected: %s", p.Identity())
p.OnTrackPublished(func(pub *lksdk.RemoteTrackPublication) {
log.Printf("track published by %s: %s (sid=%s)", p.Identity(), pub.Name(), pub.SID())
// attempt to subscribe (logs will show subscription outcome)
if _, err := p.GetOrSubscribeTrack(pub.SID(), nil); err != nil {
log.Printf("subscribe fail: %v", err)
}
})
})
room.OnTrackSubscribed(func(track *lksdk.RemoteTrack, pub *lksdk.RemoteTrackPublication, rp *lksdk.RemoteParticipant) {
log.Printf("subscribed to track %s from %s", pub.Name(), rp.Identity())
})
room.OnTrackUnsubscribed(func(track *lksdk.RemoteTrack, pub *lksdk.RemoteTrackPublication, rp *lksdk.RemoteParticipant) {
log.Printf("unsubscribed from track %s from %s", pub.Name(), rp.Identity())
})
// publish an Opus audio source (sine wave) via the server SDK publisher helper
source := lksdk.NewAudioSource(48000, 1) // 48kHz mono for Opus
if _, err := room.LocalParticipant.PublishAudioTrack(source, &lksdk.TrackPublishOptions{
Name: "agent-opus",
Source: livekit.TrackSource_MICROPHONE,
}); err != nil {
log.Fatalf("publish audio failed: %v", err)
}
log.Println("published opus audio track: agent-opus")
// generate 20ms frames (960 samples @48kHz) and write to source
go func() {
t := 0.0
tick := time.NewTicker(20 * time.Millisecond)
defer tick.Stop()
for range tick.C {
frame := make([]int16, 960)
for i := range frame {
frame[i] = int16(math.Sin(t) * 15000)
t += 2 * math.Pi * 440 / 48000 // 440Hz tone
}
source.WriteFrame(frame) // writes PCM -> encoded as Opus by SDK
}
}()
// keep process alive until ctrl+c
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
}
Notes about the snippet
• Uses Opus (48 kHz) via the SDK audio source so LiveKit handles encoding/track lifecycle and timing.
• Logs participant connects, track published, subscribe/unsubscribe events — these logs will show whether the SIP gateway subscribes to your track.
• Replace connection URL / credentials with your environment.
What to paste for SDP or PCAP analysis
• Full SDP offer and answer text (both sides) for the failing call.
• OR a short packet capture with the call's SDP exchange and RTP (pcap/pcapng). If you paste a pcap summary, include:
◦ SIP INVITE/200/ACK messages (text)
◦ SDP blocks from Offer/Answer
◦ A few RTP packet headers showing payload type, SSRC, sequence numbers, and timestamps
What I’ll check once you paste them
• Presence and mapping of Opus or PCMA in the SDP (rtpmap/fmtp).
• Payload-type numbers and clock rates (e.g., Opus 48000/2, PCMA static PT=8 @8000).
• Whether the SIP gateway actually subscribes to your LiveKit track (no subscribe events in logs).
• RTP packets on the wire: correct payload types, incrementing seq, matching SSRC/pt, and whether they reach the gateway IP.
• Any DTLS/SRTP mismatches or ICE candidate omissions visible in the SDP.
Paste your SDP offer/answer (or a pcap) and I’ll point out suspicious fields and next steps.