feat: implement AI-orchestrated result extraction and service connectivity tests

This commit is contained in:
2026-08-27 17:45:07 +05:30
parent 59c1372fe3
commit 3d2596ced1
11 changed files with 546 additions and 123 deletions
@@ -130,9 +130,14 @@ async def voice_turn(
detail="Voice onboarding session is not active",
)
# 2. Transcribe speech if audio provided with multi-model Indic recognition
# 2. Fast-path transcript: use real-time Web Speech text_fallback first for zero-latency processing
patient_transcript = ""
if audio:
if text_fallback and text_fallback.strip():
from app.services.medical_speech_normalizer import normalize_medical_speech
patient_transcript = normalize_medical_speech(text_fallback.strip(), language_code=session.language)
# If text_fallback was not available, run server-side multi-model STT
if not patient_transcript and audio:
audio_bytes = await audio.read()
if len(audio_bytes) > 0:
patient_transcript = await voice_service.speech_to_text(
@@ -147,18 +152,35 @@ async def voice_turn(
},
)
# If backend STT is empty, use frontend real-time transcript fallback
if (not patient_transcript or not patient_transcript.strip()) and text_fallback and text_fallback.strip():
from app.services.medical_speech_normalizer import normalize_medical_speech
patient_transcript = normalize_medical_speech(text_fallback.strip(), language_code=session.language)
# If STILL empty, user spoke nothing or silence was recorded.
# Do NOT substitute fake default text or auto-fill clinical fields!
if not patient_transcript or not patient_transcript.strip():
if session.language.startswith("ta"):
patient_transcript = "எனக்கு உடல்நலக்குறைவு உள்ளது."
elif session.language.startswith("hi"):
patient_transcript = "मुझे स्वास्थ्य संबंधी समस्या है।"
lang = session.language.lower()
if lang.startswith("ta"):
no_speech_msg = "மன்னிக்கவும், உங்கள் குரல் கேட்கவில்லை. தயவுசெய்து உங்கள் உடல்நலப் பிரச்சினை பற்றி பேசவும்."
elif lang.startswith("hi"):
no_speech_msg = "क्षमा करें, मुझे आपकी आवाज़ सुनाई नहीं दी। कृपया अपनी स्वास्थ्य समस्या के बारे में बोलें।"
elif lang.startswith("te"):
no_speech_msg = "క్షమించండి, మీ ధ్వని వినిపించలేదు. దయచేసి మీ ఆరోగ్య సమస్య గురించి మాట్లాడండి."
elif lang.startswith("kn"):
no_speech_msg = "ಕ್ಷಮಿಸಿ, ನಿಮ್ಮ ಧ್ವನಿ ಕೇಳಿಸಲಿಲ್ಲ. ದಯವಿಟ್ಟು ನಿಮ್ಮ ಆರೋಗ್ಯದ ತೊಂದರೆ ಬಗ್ಗೆ ಮಾತನಾಡಿ."
else:
patient_transcript = "I am experiencing symptoms."
no_speech_msg = "I didn't hear anything. Please speak into your microphone and describe your health symptoms."
audio_id, _ = await voice_service.text_to_speech(
text=no_speech_msg,
language_code=session.language,
)
return VoiceTurnResponse(
success=True,
session_id=session_id,
patient_transcript="",
ai_text=no_speech_msg,
stage=session.stage,
completed=False,
audio_url=f"/v1/voice-onboarding/audio/{audio_id}",
)