debug: add audio frame counters to relay for troubleshooting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hailin 2026-04-06 05:22:52 -07:00
parent ec17c085b2
commit bbdb59cc05
1 changed files with 12 additions and 0 deletions

View File

@ -145,6 +145,8 @@ class Relay:
self._inject_buf = np.array([], dtype=np.int16) self._inject_buf = np.array([], dtype=np.int16)
# Buffer for speaker PCM to accumulate before encoding # Buffer for speaker PCM to accumulate before encoding
self._speaker_buf = np.array([], dtype=np.int16) self._speaker_buf = np.array([], dtype=np.int16)
self._audio_in_count = 0
self._audio_out_count = 0
async def handle_esp32(self, websocket): async def handle_esp32(self, websocket):
"""Handle one ESP32 WebSocket connection.""" """Handle one ESP32 WebSocket connection."""
@ -218,6 +220,10 @@ class Relay:
async def _handle_audio(self, opus_data): async def _handle_audio(self, opus_data):
"""Decode Opus from ESP32, resample, inject into voice_bridge.""" """Decode Opus from ESP32, resample, inject into voice_bridge."""
try: 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 # Decode Opus → PCM 16kHz mono
pcm = self.opus_decoder.decode(opus_data, ESP_FRAME_SIZE) pcm = self.opus_decoder.decode(opus_data, ESP_FRAME_SIZE)
samples = np.frombuffer(pcm, dtype=np.int16) samples = np.frombuffer(pcm, dtype=np.int16)
@ -240,6 +246,12 @@ class Relay:
if not self.ws or self.ws.closed: if not self.ws or self.ws.closed:
return return
try: 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) samples = np.frombuffer(pcm_bytes, dtype=np.int16)
# Resample 48kHz → 16kHz # Resample 48kHz → 16kHz