Peter Michael Gits Claude commited on
Commit
628e022
Β·
1 Parent(s): 4a7e625

feat: Add STT service preload to prevent cold start delays

Browse files

- Add _preload_stt_service() method to warm up STT model during VoiceCal startup
- Call /preload?model_size=base endpoint to trigger model loading
- Prevent WebSocket HTTP 503 errors caused by cold-starting STT service
- Add timeout handling and detailed logging for preload process
- Update to v0.8.3 with STT service preload warming

Resolves the timing issue where VoiceCal tries to connect before STT service is ready.

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

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

Files changed (2) hide show
  1. core/mcp_audio_handler.py +36 -0
  2. version.py +2 -2
core/mcp_audio_handler.py CHANGED
@@ -131,6 +131,10 @@ class MCPAudioHandler:
131
  self.stt_http_url = self._find_working_http_endpoint(stt_http_urls, "STT")
132
  self.tts_http_url = self._find_working_http_endpoint(tts_urls, "TTS")
133
 
 
 
 
 
134
  # Check if we have any working STT service (WebSocket preferred, HTTP fallback)
135
  if self.stt_websocket_urls or self.stt_http_url:
136
  print("πŸ”§ WEBSOCKET/HTTP FALLBACK: STT service available")
@@ -143,6 +147,38 @@ class MCPAudioHandler:
143
  except Exception as e:
144
  print(f"πŸ”§ WEBSOCKET/HTTP FALLBACK ERROR: {e}")
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  def _find_working_http_endpoint(self, urls: list, service_name: str) -> str:
147
  """Find working HTTP endpoint for fallback."""
148
  import requests
 
131
  self.stt_http_url = self._find_working_http_endpoint(stt_http_urls, "STT")
132
  self.tts_http_url = self._find_working_http_endpoint(tts_urls, "TTS")
133
 
134
+ # Preload STT service to warm up the model and avoid cold start delays
135
+ if self.stt_http_url:
136
+ self._preload_stt_service()
137
+
138
  # Check if we have any working STT service (WebSocket preferred, HTTP fallback)
139
  if self.stt_websocket_urls or self.stt_http_url:
140
  print("πŸ”§ WEBSOCKET/HTTP FALLBACK: STT service available")
 
147
  except Exception as e:
148
  print(f"πŸ”§ WEBSOCKET/HTTP FALLBACK ERROR: {e}")
149
 
150
+ def _preload_stt_service(self):
151
+ """Preload STT service to warm up the model and avoid cold start delays."""
152
+ try:
153
+ import requests
154
+ import time
155
+
156
+ preload_url = f"{self.stt_http_url}/preload?model_size=base"
157
+ print(f"πŸ”§ STT PRELOAD: Warming up STT service at {preload_url}")
158
+
159
+ start_time = time.time()
160
+ response = requests.get(preload_url, timeout=30)
161
+ elapsed_time = time.time() - start_time
162
+
163
+ if response.status_code == 200:
164
+ result = response.json()
165
+ if result.get("status") == "success":
166
+ print(f"βœ… STT PRELOAD: Model loaded successfully in {elapsed_time:.1f}s - {result.get('message', 'Ready')}")
167
+ logger.info(f"STT service preloaded successfully: {result.get('message')}")
168
+ else:
169
+ print(f"⚠️ STT PRELOAD: {result.get('message', 'Unknown response')}")
170
+ logger.warning(f"STT preload response: {result}")
171
+ else:
172
+ print(f"⚠️ STT PRELOAD: HTTP {response.status_code} - Service may still be starting")
173
+ logger.warning(f"STT preload failed: HTTP {response.status_code}")
174
+
175
+ except requests.exceptions.Timeout:
176
+ print(f"⏰ STT PRELOAD: Timeout after 30s - Service may be cold starting, will try again later")
177
+ logger.warning("STT preload timed out - service may be cold starting")
178
+ except Exception as e:
179
+ print(f"⚠️ STT PRELOAD: Error warming up service - {e}")
180
+ logger.warning(f"STT preload error: {e}")
181
+
182
  def _find_working_http_endpoint(self, urls: list, service_name: str) -> str:
183
  """Find working HTTP endpoint for fallback."""
184
  import requests
version.py CHANGED
@@ -2,9 +2,9 @@
2
  Version information for ChatCal Voice-Enabled AI Assistant
3
  """
4
 
5
- __version__ = "0.8.2"
6
  __build_date__ = "2025-08-23T04:00:00"
7
- __description__ = "VoiceCal - Voice-Enabled AI Scheduling Assistant with WebSocket STT integration and Gradio fallback mechanisms"
8
 
9
  def get_version_info():
10
  """Get detailed version information"""
 
2
  Version information for ChatCal Voice-Enabled AI Assistant
3
  """
4
 
5
+ __version__ = "0.8.3"
6
  __build_date__ = "2025-08-23T04:00:00"
7
+ __description__ = "VoiceCal - Voice-Enabled AI Scheduling Assistant with STT service preload warming to prevent cold start delays"
8
 
9
  def get_version_info():
10
  """Get detailed version information"""