The NLP Track processes speech-to-text transcripts through multiple language agents to extract semantic meaning, classify emergencies, and generate summaries.
from app.agents.summary import generate_summarysummary = await generate_summary( transcript="My dad is clutching his chest and can't breathe...", category="EMS", tags=["CARDIAC_EVENT", "BREATHING_DIFFICULTY"])# Returns: "Caller reports father experiencing chest pain and difficulty breathing."
The NLP track handles streaming transcripts with incremental updates:
def on_partial_transcript(text: str, call_id: str): """ Process partial transcript for quick initial classification. Called by STT client as speech is recognized. """ if len(text) < 20: # Wait for meaningful text return # Quick classification from partial text service = classify_service_and_tags(text, distress=0.5) # Update dispatcher UI immediately update_live_signal(call_id, { "service_preliminary": service['category'], "tags_preliminary": service['tags'][:3] # Top 3 tags })def on_final_transcript(text: str, call_id: str): """ Process complete transcript for full analysis. Called when speech segment is finalized. """ # Run complete pipeline results = await process_text(text, distress=get_distress(call_id)) # Update with final results update_live_signal(call_id, results)
@pytest.mark.asyncioasync def test_full_nlp_pipeline(): """Test complete flow from transcript to final results""" # Simulate streaming transcript partial = "Someone's been" final = "Someone's been shot and they're not breathing" # Partial processing partial_result = await process_text(partial, distress=0.6) assert partial_result['service'] in ['EMS', 'OTHER'] # Final processing should be more accurate final_result = await process_text(final, distress=0.9) assert final_result['service'] == 'EMS' assert 'ACTIVE_SHOOTER' in final_result['tags'] assert 'NOT_BREATHING' in final_result['tags'] assert final_result['confidence'] > 0.8