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>
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
|
|
|
|
|
|
|
|
|
|
| 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):
|