Peter Michael Gits Claude commited on
Commit
57bc78b
Β·
1 Parent(s): f118868

feat: Add enhanced TTS connection error handling and diagnostics

Browse files

- Add timeout handling for TTS WebSocket connections
- Improve error messages with specific diagnostic hints
- Detect when TTS service is in wrong mode (Gradio vs WebSocket)
- Guide users to set TTS_SERVICE_MODE=websocket environment variable
- Better debugging for TTS connection failures

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. webrtc/server/websocket_handler.py +15 -3
webrtc/server/websocket_handler.py CHANGED
@@ -221,12 +221,15 @@ class WebRTCHandler:
221
  try:
222
  logger.info(f"πŸ”Œ Connecting to TTS service for client {client_id}: {self.tts_websocket_url}")
223
 
224
- # Connect to TTS WebSocket service
225
- tts_ws = await websockets.connect(self.tts_websocket_url)
 
 
 
226
  self.tts_connections[client_id] = tts_ws
227
 
228
  # Wait for connection confirmation
229
- confirmation = await tts_ws.recv()
230
  confirmation_data = json.loads(confirmation)
231
 
232
  if confirmation_data.get("type") == "tts_connection_confirmed":
@@ -236,8 +239,17 @@ class WebRTCHandler:
236
  logger.warning(f"⚠️ Unexpected TTS confirmation: {confirmation_data}")
237
  return False
238
 
 
 
 
 
 
 
 
 
239
  except Exception as e:
240
  logger.error(f"❌ Failed to connect to TTS service for {client_id}: {e}")
 
241
  return False
242
 
243
  async def disconnect_from_tts_service(self, client_id: str):
 
221
  try:
222
  logger.info(f"πŸ”Œ Connecting to TTS service for client {client_id}: {self.tts_websocket_url}")
223
 
224
+ # Connect to TTS WebSocket service with timeout
225
+ tts_ws = await asyncio.wait_for(
226
+ websockets.connect(self.tts_websocket_url),
227
+ timeout=10.0
228
+ )
229
  self.tts_connections[client_id] = tts_ws
230
 
231
  # Wait for connection confirmation
232
+ confirmation = await asyncio.wait_for(tts_ws.recv(), timeout=15.0)
233
  confirmation_data = json.loads(confirmation)
234
 
235
  if confirmation_data.get("type") == "tts_connection_confirmed":
 
239
  logger.warning(f"⚠️ Unexpected TTS confirmation: {confirmation_data}")
240
  return False
241
 
242
+ except asyncio.TimeoutError:
243
+ logger.error(f"❌ TTS service connection timeout - service may not be in WebSocket mode")
244
+ logger.info(f"πŸ’‘ TTS service needs TTS_SERVICE_MODE=websocket environment variable")
245
+ return False
246
+ except websockets.exceptions.InvalidStatusCode as e:
247
+ logger.error(f"❌ TTS WebSocket endpoint not available: {e}")
248
+ logger.info(f"πŸ’‘ TTS service may be running in Gradio-only mode instead of WebSocket mode")
249
+ return False
250
  except Exception as e:
251
  logger.error(f"❌ Failed to connect to TTS service for {client_id}: {e}")
252
+ logger.info(f"πŸ’‘ Check if TTS service is running and configured with TTS_SERVICE_MODE=websocket")
253
  return False
254
 
255
  async def disconnect_from_tts_service(self, client_id: str):