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:
@@ -433,7 +433,11 @@ class AssemblyAISTTService(WebsocketSTTService):
|
||||
while len(self._audio_buffer) >= self._chunk_size_bytes:
|
||||
chunk = bytes(self._audio_buffer[: self._chunk_size_bytes])
|
||||
self._audio_buffer = self._audio_buffer[self._chunk_size_bytes :]
|
||||
await self._websocket.send(chunk)
|
||||
try:
|
||||
await self._websocket.send(chunk)
|
||||
except Exception as e:
|
||||
logger.warning(f"{self}: send failed: {e}")
|
||||
break
|
||||
|
||||
yield None
|
||||
|
||||
|
||||
@@ -290,7 +290,10 @@ class CartesiaSTTService(WebsocketSTTService):
|
||||
if not self._websocket or self._websocket.state is not State.OPEN:
|
||||
await self._connect()
|
||||
|
||||
await self._websocket.send(audio)
|
||||
try:
|
||||
await self._websocket.send(audio)
|
||||
except Exception as e:
|
||||
logger.warning(f"{self}: send failed: {e}")
|
||||
yield None
|
||||
|
||||
async def _connect(self):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -412,7 +412,10 @@ class SonioxSTTService(WebsocketSTTService):
|
||||
Frame: None (transcription results come via WebSocket callbacks).
|
||||
"""
|
||||
if self._websocket and self._websocket.state is State.OPEN:
|
||||
await self._websocket.send(audio)
|
||||
try:
|
||||
await self._websocket.send(audio)
|
||||
except Exception as e:
|
||||
logger.warning(f"{self}: send failed: {e}")
|
||||
|
||||
yield None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user