Add debug logging and safety for piggybacked recording

- Log chunk count and peak audio level on recording stop
- Add null check on _recorded_audio in callback
- Small delay after stopping piggybacked recording for callback to finish

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 17:11:51 -07:00
parent 6a56967540
commit 9c5f7c5cfe

View File

@@ -197,14 +197,18 @@ class AudioService:
if self._record_thread: if self._record_thread:
self._record_thread.join(timeout=2.0) self._record_thread.join(timeout=2.0)
self._record_thread = None self._record_thread = None
else:
# Piggybacking on host stream — give callback a moment to finish
time.sleep(0.05)
if not self._recorded_audio: if not self._recorded_audio:
print(f"Recording stopped: NO audio chunks captured (piggyback={self._host_stream is not None})")
return b"" return b""
# Combine all chunks # Combine all chunks
audio = np.concatenate(self._recorded_audio) audio = np.concatenate(self._recorded_audio)
device_sr = getattr(self, '_record_device_sr', 48000) device_sr = getattr(self, '_record_device_sr', 48000)
print(f"Recording stopped: {len(audio)} samples @ {device_sr}Hz ({len(audio)/device_sr:.2f}s)") print(f"Recording stopped: {len(audio)} samples @ {device_sr}Hz ({len(audio)/device_sr:.2f}s), chunks={len(self._recorded_audio)}, peak={np.abs(audio).max():.4f}")
# Resample to 16kHz for Whisper # Resample to 16kHz for Whisper
if device_sr != 16000: if device_sr != 16000:
@@ -466,7 +470,7 @@ class AudioService:
def callback(indata, frames, time_info, status): def callback(indata, frames, time_info, status):
# Capture for push-to-talk recording if active # Capture for push-to-talk recording if active
if self._recording: if self._recording and self._recorded_audio is not None:
self._recorded_audio.append(indata[:, record_channel].copy()) self._recorded_audio.append(indata[:, record_channel].copy())
if not self._host_send_callback: if not self._host_send_callback: