Peter Michael Gits Claude commited on
Commit Β·
4cf4588
1
Parent(s): 9a4b253
feat: Remove all demo simulation code - REAL STT ONLY v0.6.0
Browse filesMAJOR CHANGE: Complete removal of demo/simulation modes
- Remove all _simulate_stt() and _simulate_stt_with_length() methods
- Remove demo_mode flags and logic throughout MCPAudioHandler
- Force voiceCal to only use real STT services (WebSocket/MCP/HTTP)
- Return clear error messages when STT services fail instead of fake responses
- Update version to 0.6.0 for this breaking change
- No more confusing demo transcriptions that mask real issues
Real Services Only:
β
WebSocket STT (primary)
β
MCP STT (fallback)
β
HTTP STT (final fallback)
β No demo/simulation modes
π€ Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- core/mcp_audio_handler.py +32 -62
- version.py +1 -1
core/mcp_audio_handler.py
CHANGED
|
@@ -21,11 +21,10 @@ class MCPAudioHandler:
|
|
| 21 |
"""Handles audio processing using MCP services."""
|
| 22 |
|
| 23 |
def __init__(self):
|
| 24 |
-
self.demo_mode = False # NEVER use demo mode - always call real services
|
| 25 |
self.stt_service = None
|
| 26 |
self.tts_service = None
|
| 27 |
|
| 28 |
-
# Initialize real services only
|
| 29 |
self._initialize_real_services()
|
| 30 |
|
| 31 |
def _initialize_real_services(self):
|
|
@@ -134,13 +133,12 @@ class MCPAudioHandler:
|
|
| 134 |
|
| 135 |
# Check if we have any working STT service (WebSocket preferred, HTTP fallback)
|
| 136 |
if self.stt_websocket_urls or self.stt_http_url:
|
| 137 |
-
print("π§ WEBSOCKET/HTTP FALLBACK: STT service available
|
| 138 |
-
self.demo_mode = False # Exit demo mode when we have working STT
|
| 139 |
|
| 140 |
if self.stt_http_url or self.tts_http_url or self.stt_websocket_urls:
|
| 141 |
print("π§ WEBSOCKET/HTTP FALLBACK: Services available")
|
| 142 |
else:
|
| 143 |
-
print("π§ WEBSOCKET/HTTP FALLBACK: No services available -
|
| 144 |
|
| 145 |
except Exception as e:
|
| 146 |
print(f"π§ WEBSOCKET/HTTP FALLBACK ERROR: {e}")
|
|
@@ -215,12 +213,12 @@ class MCPAudioHandler:
|
|
| 215 |
}
|
| 216 |
|
| 217 |
async def speech_to_text(self, audio_file_path: str) -> str:
|
| 218 |
-
"""Convert speech to text using
|
| 219 |
try:
|
| 220 |
print(f"π€ STT: Processing audio file: {audio_file_path}")
|
| 221 |
|
| 222 |
# First try WebSocket connection (unmute.sh methodology)
|
| 223 |
-
if hasattr(self, 'stt_websocket_urls') and self.stt_websocket_urls
|
| 224 |
print(f"π€ STT: Trying WebSocket connection (unmute.sh style)")
|
| 225 |
result = await self._call_websocket_stt_service(audio_file_path)
|
| 226 |
if result and not result.startswith("Error"):
|
|
@@ -229,15 +227,18 @@ class MCPAudioHandler:
|
|
| 229 |
else:
|
| 230 |
print(f"π€ STT: WebSocket FAILED - {result}")
|
| 231 |
|
| 232 |
-
# Try MCP service if available
|
| 233 |
-
if
|
| 234 |
print(f"π€ STT: Calling MCP STT service")
|
| 235 |
result = await self._call_mcp_stt_service(audio_file_path)
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
# HTTP fallback if WebSocket and MCP failed
|
| 240 |
-
if hasattr(self, 'stt_http_url') and self.stt_http_url
|
| 241 |
print(f"π€ STT: Using HTTP fallback service at {self.stt_http_url}")
|
| 242 |
result = await self._call_http_stt_service(audio_file_path)
|
| 243 |
if result and not result.startswith("Error"):
|
|
@@ -246,16 +247,17 @@ class MCPAudioHandler:
|
|
| 246 |
else:
|
| 247 |
print(f"π€ STT: HTTP FAILED - {result}")
|
| 248 |
|
| 249 |
-
#
|
| 250 |
-
|
| 251 |
-
|
|
|
|
| 252 |
|
| 253 |
except Exception as e:
|
| 254 |
print(f"π€ STT ERROR: {e}")
|
| 255 |
import traceback
|
| 256 |
traceback.print_exc()
|
| 257 |
logger.error(f"STT error: {e}")
|
| 258 |
-
return
|
| 259 |
|
| 260 |
async def _call_websocket_stt_service(self, audio_file_path: str) -> str:
|
| 261 |
"""Call STT service via WebSocket using unmute.sh methodology."""
|
|
@@ -356,11 +358,9 @@ class MCPAudioHandler:
|
|
| 356 |
if hasattr(self, 'stt_http_url') and self.stt_http_url:
|
| 357 |
return await self._call_http_stt_service(audio_file_path)
|
| 358 |
|
| 359 |
-
#
|
| 360 |
-
print(f"π€ MCP STT:
|
| 361 |
-
|
| 362 |
-
result = self._simulate_stt_with_length(audio_duration)
|
| 363 |
-
return f"{result} [MCP framework ready]"
|
| 364 |
|
| 365 |
except ImportError:
|
| 366 |
print(f"π€ MCP STT: MCP client not available, trying HTTP fallback")
|
|
@@ -369,13 +369,12 @@ class MCPAudioHandler:
|
|
| 369 |
if hasattr(self, 'stt_http_url') and self.stt_http_url:
|
| 370 |
return await self._call_http_stt_service(audio_file_path)
|
| 371 |
|
| 372 |
-
#
|
| 373 |
-
|
| 374 |
-
return self._simulate_stt_with_length(audio_duration)
|
| 375 |
|
| 376 |
except Exception as e:
|
| 377 |
print(f"π€ MCP STT service call error: {e}")
|
| 378 |
-
return "MCP STT service error"
|
| 379 |
|
| 380 |
async def _call_http_stt_service(self, audio_file_path: str) -> str:
|
| 381 |
"""Call STT service via HTTP as fallback."""
|
|
@@ -510,29 +509,6 @@ class MCPAudioHandler:
|
|
| 510 |
except:
|
| 511 |
return 5.0 # Default duration
|
| 512 |
|
| 513 |
-
def _simulate_stt(self, audio_data) -> str:
|
| 514 |
-
"""Simulate speech-to-text for demo purposes."""
|
| 515 |
-
demo_transcriptions = [
|
| 516 |
-
"Hi, I'm John Smith. I'd like to book a 30-minute meeting with Peter tomorrow at 2 PM.",
|
| 517 |
-
"Hello, this is Sarah. Can we schedule a Google Meet for next Tuesday?",
|
| 518 |
-
"I'm Mike Johnson. Please book an appointment for Friday afternoon.",
|
| 519 |
-
"Hi there! I need to schedule a one-hour consultation about my project.",
|
| 520 |
-
"Good morning, I'd like to check Peter's availability this week."
|
| 521 |
-
]
|
| 522 |
-
|
| 523 |
-
import random
|
| 524 |
-
return random.choice(demo_transcriptions)
|
| 525 |
-
|
| 526 |
-
def _simulate_stt_with_length(self, duration: float) -> str:
|
| 527 |
-
"""Simulate STT with duration-appropriate responses."""
|
| 528 |
-
if duration < 2:
|
| 529 |
-
return "Hello via MCP"
|
| 530 |
-
elif duration < 5:
|
| 531 |
-
return "Hi, I'm testing the MCP voice input"
|
| 532 |
-
elif duration < 10:
|
| 533 |
-
return "Hi, I'm John Smith. I'd like to book a meeting with Peter via MCP."
|
| 534 |
-
else:
|
| 535 |
-
return "Hi, I'm John Smith. I'd like to book a 30-minute meeting with Peter tomorrow at 2 PM via MCP service."
|
| 536 |
|
| 537 |
def process_audio_input(self, audio_tuple: Tuple) -> str:
|
| 538 |
"""Process Gradio audio input format using MCP."""
|
|
@@ -550,12 +526,6 @@ class MCPAudioHandler:
|
|
| 550 |
if isinstance(audio_array, np.ndarray):
|
| 551 |
print(f"π€ MCP HANDLER: Audio array shape: {audio_array.shape}")
|
| 552 |
|
| 553 |
-
# For demo mode, use duration-aware simulation
|
| 554 |
-
if self.demo_mode:
|
| 555 |
-
print(f"π€ MCP HANDLER: Using MCP demo mode")
|
| 556 |
-
audio_duration = len(audio_array) / sample_rate
|
| 557 |
-
print(f"π€ MCP HANDLER: Audio duration: {audio_duration:.2f} seconds")
|
| 558 |
-
return self._simulate_stt_with_length(audio_duration)
|
| 559 |
|
| 560 |
# Process with MCP STT service
|
| 561 |
try:
|
|
@@ -564,9 +534,9 @@ class MCPAudioHandler:
|
|
| 564 |
audio_normalized = (audio_array * 32767).astype(np.int16)
|
| 565 |
except ValueError as buffer_error:
|
| 566 |
if "buffer size must be a multiple of element size" in str(buffer_error):
|
| 567 |
-
print(f"π€ MCP HANDLER: Buffer size error -
|
| 568 |
audio_duration = len(audio_array) / sample_rate if len(audio_array) > 0 else 1.0
|
| 569 |
-
return f"
|
| 570 |
else:
|
| 571 |
raise buffer_error
|
| 572 |
|
|
@@ -599,7 +569,7 @@ class MCPAudioHandler:
|
|
| 599 |
pass # Ignore cleanup errors
|
| 600 |
except Exception as stt_error:
|
| 601 |
print(f"π€ MCP HANDLER ERROR: MCP STT processing failed: {stt_error}")
|
| 602 |
-
return
|
| 603 |
|
| 604 |
print(f"π€ MCP HANDLER: Invalid audio array format")
|
| 605 |
return "Invalid audio format"
|
|
@@ -617,8 +587,8 @@ class MCPAudioHandler:
|
|
| 617 |
if not config.enable_voice_responses:
|
| 618 |
return None
|
| 619 |
|
| 620 |
-
if
|
| 621 |
-
print(f"π MCP TTS:
|
| 622 |
return None
|
| 623 |
|
| 624 |
print(f"π MCP TTS: Converting text to speech via MCP: {text[:50]}...")
|
|
@@ -653,8 +623,8 @@ class MCPAudioHandler:
|
|
| 653 |
|
| 654 |
def is_audio_service_available(self) -> Tuple[bool, bool]:
|
| 655 |
"""Check if MCP STT and TTS services are available."""
|
| 656 |
-
stt_available = bool(self.stt_service
|
| 657 |
-
tts_available = bool(self.tts_service
|
| 658 |
return stt_available, tts_available
|
| 659 |
|
| 660 |
def get_audio_status(self) -> dict:
|
|
@@ -664,7 +634,7 @@ class MCPAudioHandler:
|
|
| 664 |
return {
|
| 665 |
"stt_available": stt_available,
|
| 666 |
"tts_available": tts_available,
|
| 667 |
-
"demo_mode":
|
| 668 |
"voice_responses_enabled": config.enable_voice_responses,
|
| 669 |
"default_voice": config.default_voice,
|
| 670 |
"service_type": "mcp"
|
|
|
|
| 21 |
"""Handles audio processing using MCP services."""
|
| 22 |
|
| 23 |
def __init__(self):
|
|
|
|
| 24 |
self.stt_service = None
|
| 25 |
self.tts_service = None
|
| 26 |
|
| 27 |
+
# Initialize real services only - NO DEMO MODE
|
| 28 |
self._initialize_real_services()
|
| 29 |
|
| 30 |
def _initialize_real_services(self):
|
|
|
|
| 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")
|
|
|
|
| 137 |
|
| 138 |
if self.stt_http_url or self.tts_http_url or self.stt_websocket_urls:
|
| 139 |
print("π§ WEBSOCKET/HTTP FALLBACK: Services available")
|
| 140 |
else:
|
| 141 |
+
print("π§ WEBSOCKET/HTTP FALLBACK: No services available - WILL RETURN ERRORS")
|
| 142 |
|
| 143 |
except Exception as e:
|
| 144 |
print(f"π§ WEBSOCKET/HTTP FALLBACK ERROR: {e}")
|
|
|
|
| 213 |
}
|
| 214 |
|
| 215 |
async def speech_to_text(self, audio_file_path: str) -> str:
|
| 216 |
+
"""Convert speech to text using REAL SERVICES ONLY - no demo mode."""
|
| 217 |
try:
|
| 218 |
print(f"π€ STT: Processing audio file: {audio_file_path}")
|
| 219 |
|
| 220 |
# First try WebSocket connection (unmute.sh methodology)
|
| 221 |
+
if hasattr(self, 'stt_websocket_urls') and self.stt_websocket_urls:
|
| 222 |
print(f"π€ STT: Trying WebSocket connection (unmute.sh style)")
|
| 223 |
result = await self._call_websocket_stt_service(audio_file_path)
|
| 224 |
if result and not result.startswith("Error"):
|
|
|
|
| 227 |
else:
|
| 228 |
print(f"π€ STT: WebSocket FAILED - {result}")
|
| 229 |
|
| 230 |
+
# Try MCP service if available
|
| 231 |
+
if self.stt_service:
|
| 232 |
print(f"π€ STT: Calling MCP STT service")
|
| 233 |
result = await self._call_mcp_stt_service(audio_file_path)
|
| 234 |
+
if result and not result.startswith("Error"):
|
| 235 |
+
print(f"π€ STT: MCP SUCCESS - {result[:50]}...")
|
| 236 |
+
return result
|
| 237 |
+
else:
|
| 238 |
+
print(f"π€ STT: MCP FAILED - {result}")
|
| 239 |
|
| 240 |
# HTTP fallback if WebSocket and MCP failed
|
| 241 |
+
if hasattr(self, 'stt_http_url') and self.stt_http_url:
|
| 242 |
print(f"π€ STT: Using HTTP fallback service at {self.stt_http_url}")
|
| 243 |
result = await self._call_http_stt_service(audio_file_path)
|
| 244 |
if result and not result.startswith("Error"):
|
|
|
|
| 247 |
else:
|
| 248 |
print(f"π€ STT: HTTP FAILED - {result}")
|
| 249 |
|
| 250 |
+
# NO DEMO MODE - Return error if all services failed
|
| 251 |
+
error_msg = "ERROR: All STT services failed - no demo mode available"
|
| 252 |
+
print(f"π€ STT: {error_msg}")
|
| 253 |
+
return error_msg
|
| 254 |
|
| 255 |
except Exception as e:
|
| 256 |
print(f"π€ STT ERROR: {e}")
|
| 257 |
import traceback
|
| 258 |
traceback.print_exc()
|
| 259 |
logger.error(f"STT error: {e}")
|
| 260 |
+
return f"ERROR: STT processing failed - {str(e)}"
|
| 261 |
|
| 262 |
async def _call_websocket_stt_service(self, audio_file_path: str) -> str:
|
| 263 |
"""Call STT service via WebSocket using unmute.sh methodology."""
|
|
|
|
| 358 |
if hasattr(self, 'stt_http_url') and self.stt_http_url:
|
| 359 |
return await self._call_http_stt_service(audio_file_path)
|
| 360 |
|
| 361 |
+
# Return error - no simulation
|
| 362 |
+
print(f"π€ MCP STT: No MCP client available")
|
| 363 |
+
return "ERROR: MCP STT service failed - no demo mode"
|
|
|
|
|
|
|
| 364 |
|
| 365 |
except ImportError:
|
| 366 |
print(f"π€ MCP STT: MCP client not available, trying HTTP fallback")
|
|
|
|
| 369 |
if hasattr(self, 'stt_http_url') and self.stt_http_url:
|
| 370 |
return await self._call_http_stt_service(audio_file_path)
|
| 371 |
|
| 372 |
+
# Return error - no simulation
|
| 373 |
+
return "ERROR: No STT services available"
|
|
|
|
| 374 |
|
| 375 |
except Exception as e:
|
| 376 |
print(f"π€ MCP STT service call error: {e}")
|
| 377 |
+
return f"ERROR: MCP STT service error - {str(e)}"
|
| 378 |
|
| 379 |
async def _call_http_stt_service(self, audio_file_path: str) -> str:
|
| 380 |
"""Call STT service via HTTP as fallback."""
|
|
|
|
| 509 |
except:
|
| 510 |
return 5.0 # Default duration
|
| 511 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
|
| 513 |
def process_audio_input(self, audio_tuple: Tuple) -> str:
|
| 514 |
"""Process Gradio audio input format using MCP."""
|
|
|
|
| 526 |
if isinstance(audio_array, np.ndarray):
|
| 527 |
print(f"π€ MCP HANDLER: Audio array shape: {audio_array.shape}")
|
| 528 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
|
| 530 |
# Process with MCP STT service
|
| 531 |
try:
|
|
|
|
| 534 |
audio_normalized = (audio_array * 32767).astype(np.int16)
|
| 535 |
except ValueError as buffer_error:
|
| 536 |
if "buffer size must be a multiple of element size" in str(buffer_error):
|
| 537 |
+
print(f"π€ MCP HANDLER: Buffer size error - returning error")
|
| 538 |
audio_duration = len(audio_array) / sample_rate if len(audio_array) > 0 else 1.0
|
| 539 |
+
return f"ERROR: Buffer size issue with audio processing ({audio_duration:.1f}s)"
|
| 540 |
else:
|
| 541 |
raise buffer_error
|
| 542 |
|
|
|
|
| 569 |
pass # Ignore cleanup errors
|
| 570 |
except Exception as stt_error:
|
| 571 |
print(f"π€ MCP HANDLER ERROR: MCP STT processing failed: {stt_error}")
|
| 572 |
+
return f"ERROR: STT processing failed - {str(stt_error)}"
|
| 573 |
|
| 574 |
print(f"π€ MCP HANDLER: Invalid audio array format")
|
| 575 |
return "Invalid audio format"
|
|
|
|
| 587 |
if not config.enable_voice_responses:
|
| 588 |
return None
|
| 589 |
|
| 590 |
+
if not self.tts_service:
|
| 591 |
+
print(f"π MCP TTS: No TTS service available")
|
| 592 |
return None
|
| 593 |
|
| 594 |
print(f"π MCP TTS: Converting text to speech via MCP: {text[:50]}...")
|
|
|
|
| 623 |
|
| 624 |
def is_audio_service_available(self) -> Tuple[bool, bool]:
|
| 625 |
"""Check if MCP STT and TTS services are available."""
|
| 626 |
+
stt_available = bool(self.stt_service)
|
| 627 |
+
tts_available = bool(self.tts_service)
|
| 628 |
return stt_available, tts_available
|
| 629 |
|
| 630 |
def get_audio_status(self) -> dict:
|
|
|
|
| 634 |
return {
|
| 635 |
"stt_available": stt_available,
|
| 636 |
"tts_available": tts_available,
|
| 637 |
+
"demo_mode": False, # NO DEMO MODE
|
| 638 |
"voice_responses_enabled": config.enable_voice_responses,
|
| 639 |
"default_voice": config.default_voice,
|
| 640 |
"service_type": "mcp"
|
version.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
Version information for ChatCal Voice-Enabled AI Assistant
|
| 3 |
"""
|
| 4 |
|
| 5 |
-
__version__ = "0.
|
| 6 |
__build_date__ = "2025-08-22T14:45:00"
|
| 7 |
__description__ = "VoiceCal - Voice-Enabled AI Scheduling Assistant with optimized WebSocket services"
|
| 8 |
|
|
|
|
| 2 |
Version information for ChatCal Voice-Enabled AI Assistant
|
| 3 |
"""
|
| 4 |
|
| 5 |
+
__version__ = "0.6.0"
|
| 6 |
__build_date__ = "2025-08-22T14:45:00"
|
| 7 |
__description__ = "VoiceCal - Voice-Enabled AI Scheduling Assistant with optimized WebSocket services"
|
| 8 |
|