listen(): make a missing-mic failure diagnosable

The error return interpolated only str(e), so exceptions that stringify to
"" (e.g. asyncio.TimeoutError) surfaced as "VAD recording failed: " with no
detail — exactly what a disconnected mic produced. Include the exception type
and a fallback hint, and reword the no-audio PlaybackError toward "is a
microphone connected?".
This commit is contained in:
Ryan Malloy 2026-07-04 12:34:12 -06:00
parent 663dc91f5b
commit da9be3a976
2 changed files with 8 additions and 3 deletions

View File

@ -331,7 +331,8 @@ async def record_audio_until_silence(
if not pcm_buf: if not pcm_buf:
raise PlaybackError( raise PlaybackError(
f"VAD recording captured no audio. Check source '{source or 'default'}'." f"No audio captured — is a microphone connected? "
f"(source '{source or 'default'}' produced no samples)"
) )
# Write the accumulated PCM as a WAV file. # Write the accumulated PCM as a WAV file.

View File

@ -895,7 +895,10 @@ async def listen(
warmup_ms=warmup_ms, warmup_ms=warmup_ms,
) )
except Exception as e: except Exception as e:
return {"error": f"VAD recording failed: {e}"} # Include the exception TYPE — some (e.g. asyncio.TimeoutError)
# stringify to "", which otherwise hides a missing-mic failure.
detail = str(e) or "no detail (often a disconnected/blocked mic)"
return {"error": f"VAD recording failed ({type(e).__name__}): {detail}"}
else: else:
await ctx.info(f"Listening for {duration_seconds:.1f}s (source={source or 'default'})...") await ctx.info(f"Listening for {duration_seconds:.1f}s (source={source or 'default'})...")
try: try:
@ -904,7 +907,8 @@ async def listen(
ready_tone=start_tone, warmup_ms=warmup_ms, ready_tone=start_tone, warmup_ms=warmup_ms,
) )
except Exception as e: except Exception as e:
return {"error": f"Recording failed: {e}"} detail = str(e) or "no detail (often a disconnected/blocked mic)"
return {"error": f"Recording failed ({type(e).__name__}): {detail}"}
# "Capture done" tone AFTER pw-record stops. Audible "over and out" # "Capture done" tone AFTER pw-record stops. Audible "over and out"
# so the user knows they can stop talking and the system is now # so the user knows they can stop talking and the system is now