From bbdb59cc05fd3331c6abbd452933af7a7c83f370 Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 6 Apr 2026 05:22:52 -0700 Subject: [PATCH] debug: add audio frame counters to relay for troubleshooting Co-Authored-By: Claude Opus 4.6 (1M context) --- relay.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/relay.py b/relay.py index bb113d5..2d9da14 100644 --- a/relay.py +++ b/relay.py @@ -145,6 +145,8 @@ class Relay: self._inject_buf = np.array([], dtype=np.int16) # Buffer for speaker PCM to accumulate before encoding self._speaker_buf = np.array([], dtype=np.int16) + self._audio_in_count = 0 + self._audio_out_count = 0 async def handle_esp32(self, websocket): """Handle one ESP32 WebSocket connection.""" @@ -218,6 +220,10 @@ class Relay: async def _handle_audio(self, opus_data): """Decode Opus from ESP32, resample, inject into voice_bridge.""" try: + self._audio_in_count += 1 + if self._audio_in_count <= 3 or self._audio_in_count % 100 == 0: + log.info(f"ESP32 audio frame #{self._audio_in_count}, size={len(opus_data)}") + # Decode Opus → PCM 16kHz mono pcm = self.opus_decoder.decode(opus_data, ESP_FRAME_SIZE) samples = np.frombuffer(pcm, dtype=np.int16) @@ -240,6 +246,12 @@ class Relay: if not self.ws or self.ws.closed: return try: + self._audio_out_count += 1 + if self._audio_out_count <= 3 or self._audio_out_count % 100 == 0: + samples_peek = np.frombuffer(pcm_bytes, dtype=np.int16) + max_amp = int(np.max(np.abs(samples_peek))) + log.info(f"Speaker frame #{self._audio_out_count}, size={len(pcm_bytes)}, max_amp={max_amp}") + samples = np.frombuffer(pcm_bytes, dtype=np.int16) # Resample 48kHz → 16kHz