Poor sound quality during AI calls traced to several bugs in pipecat-manager's media stream handling code (Go side).
Fix four issues in the Go audio pipeline:
-
Fatal error on audio write terminates output handler — A single transient write error to Asterisk kills all TTS audio for the remainder of the call. Fix: log and continue instead of returning.
-
Silent frame dropping with
time.AfterGC pressure —pushFrame()usestime.Afterper frame (~50/sec), leaking timers until they fire. Frames are dropped silently with no monitoring. Fix: non-blocking fast path + reusable timer slow path + periodic drop logging via atomic counter on Session. -
No frame drop monitoring — When audio frames are dropped due to channel backpressure, there is no logging or metrics. Fix: add atomic counter to Session, log periodically, and log total on session stop.
-
Pong routed through audio channel — Input receiver sends Pong via
SendDatawhich goes through the audio queue. In practice this is dead code (gorilla/websocket handles Ping/Pong internally via concurrent-safeWriteControl), but it is misleading and fragile. Fix: remove theSendDatacall and add a clarifying comment.
models/pipecatcall/session.go— AddDroppedFrames atomic.Int64fieldpkg/pipecatcallhandler/pipecatframe.go— RewritepushFramewith fast path and proper timer; add drop loggingpkg/pipecatcallhandler/runner.go— Log+continue on audio error instead of return; clean up Pong handlingpkg/pipecatcallhandler/session.go— Log total dropped frames on session stop
Confirmed that no resampling occurs anywhere in the pipeline under normal
operation. audio_out_sample_rate=16000 in Python ensures all TTS providers
generate 16kHz natively. Go's GetDataSamples resampler is never invoked.