Overview
MicrophoneManager controls the microphone state for a user session, managing when the smart glasses should capture and send audio. It implements intelligent debouncing, unauthorized audio detection, keep-alive mechanisms, and VAD (Voice Activity Detection) bypass for specific scenarios. File:packages/cloud/src/services/session/MicrophoneManager.ts
Key Features
- State Debouncing: Prevents rapid microphone state changes
- Keep-Alive Mechanism: Maintains microphone state during active sessions
- Unauthorized Audio Detection: Turns off mic when receiving unexpected audio
- VAD Bypass Support: Bypasses voice activity detection for PCM subscriptions
- Subscription-Based Control: Automatically manages mic based on app needs
- Cached State Management: Optimizes performance with subscription caching
Architecture
State Management
Microphone State
State Update with Debouncing
Message Format
Microphone State Change Message
Required Data Calculation
Data Type Logic
VAD Bypass Logic
Subscription Management
Cached Subscription State
Subscription Change Handler
Keep-Alive Mechanism
Keep-Alive Timer
Unauthorized Audio Detection
Detection and Response
Connection State Handling
Integration Methods
Current State Query
Audio Reception Callback
Called by AudioManager when audio is received:Configuration
Timing Constants
Lifecycle Management
Disposal
Best Practices
- Always use debouncing to prevent rapid state changes
- Cache subscription state to avoid expensive repeated lookups
- Send keep-alive messages to maintain microphone state
- Detect unauthorized audio and respond immediately
- Bypass VAD when apps need raw PCM data
- Update state on connection to ensure sync with glasses
Integration Points
- AudioManager: Notifies when audio is received
- SubscriptionService: Determines media subscription state
- TranscriptionManager: Provides cloud STT status
- WebSocket: Sends state changes to glasses
- AppManager: Updates on app subscription changes
Related Documentation
- AudioManager: Audio processing
- SubscriptionService: Subscription management
- Message Types: Microphone state messages
- WebSocket Service: Connection handling