Guard run_stt WebSocket sends with try/except

AssemblyAI, Cartesia, Gradium, and Soniox STT services sent audio over
the WebSocket without catching transient send failures, so a single
network hiccup could propagate an exception up through process_frame
and end the pipeline. Other push-based STT services (Deepgram, xAI,
Azure, Smallest, etc.) already guard their sends.

Follow the deepgram/stt.py pattern: log a warning and continue. The
existing connection-state check at the top of each call handles
recovery on the next invocation.
This commit is contained in:
Mark Backman
2026-04-22 11:03:41 -04:00
parent 08fe9157cc
commit 3b0affe5b4
4 changed files with 18 additions and 4 deletions

View File

@@ -350,7 +350,11 @@ class GradiumSTTService(WebsocketSTTService):
chunk = base64.b64encode(chunk).decode("utf-8")
msg = {"type": "audio", "audio": chunk}
if self._websocket and self._websocket.state is State.OPEN:
await self._websocket.send(json.dumps(msg))
try:
await self._websocket.send(json.dumps(msg))
except Exception as e:
logger.warning(f"{self}: send failed: {e}")
break
yield None