A TypeScript utility for tracking timing of events in a digital assistant pipeline. This utility helps identify delays between speech-to-text, LLM processing, and text-to-speech operations in a multi-session environment.
npm install performance-trackerimport { PerformanceTracker } from 'performance-tracker';
// Reset the timer for a session
PerformanceTracker.resetTimer('user123');
// Log events with timestamps
PerformanceTracker.logEvent('user123', 'STT_START');
// ... speech-to-text processing happens ...
PerformanceTracker.logEvent('user123', 'STT_END');
// Log events with custom details
PerformanceTracker.logEvent('user123', 'LLM_START', {
model: 'gpt-4',
promptTokens: 125
});
// Generate a timing report
const report = PerformanceTracker.generateReport('user123');
console.log(report);- Singleton design for application-wide access
- Session-based timing for multi-user environments
- Automatic duration calculation between start/end events
- Detailed reporting of all timing events
- Support for custom event metadata
- JSON export for integration with analytics systems
Timing Report for Session: user123
Started at: 2025-04-14T08:37:51.835Z
--------------------------------------------------
Event | Time (ms) | Duration (ms)
--------------------------------------------------
VOICE_RECEIVED | 0 | -
STT_START | 10 | -
STT_END | 330 | 320
LLM_START | 345 | -
LLM_REPLY_1 | 595 | -
TTS_REQUEST_1 | 605 | -
TTS_RESPONSE_1 | 785 | 180
LLM_REPLY_2 | 915 | -
TTS_REQUEST_2 | 925 | -
TTS_RESPONSE_2 | 1105 | 180
LLM_REPLY_3 | 1205 | -
LLM_END | 1210 | 865
TTS_REQUEST_3 | 1215 | -
TTS_RESPONSE_3 | 1395 | 180
INTERACTION_COMPLETE | 1400 | -
--------------------------------------------------
TOTAL TIME: | 1400ms
Here are some standard event names you might use:
VOICE_RECEIVED- When voice input is receivedSTT_START- Start of speech-to-text processingSTT_END- End of speech-to-text processingLLM_START- Start of LLM requestLLM_REPLY_1,LLM_REPLY_2, etc. - When chunks of the LLM response are receivedLLM_END- When LLM processing completesTTS_REQUEST_1,TTS_REQUEST_2, etc. - When text-to-speech requests are sentTTS_RESPONSE_1,TTS_RESPONSE_2, etc. - When text-to-speech responses are receivedINTERACTION_COMPLETE- When the entire interaction completes
// Get JSON data for external analysis
const data = PerformanceTracker.exportData('user123');
saveToAnalyticsSystem(data);The tracker automatically handles multiple concurrent sessions by session ID:
// Session 1
PerformanceTracker.logEvent('user123', 'STT_START');
// Session 2 (concurrent)
PerformanceTracker.logEvent('user456', 'STT_START');
// Continue tracking separately
PerformanceTracker.logEvent('user123', 'STT_END');
PerformanceTracker.logEvent('user456', 'STT_END');MIT