Skip to main content

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

  1. State Debouncing: Prevents rapid microphone state changes
  2. Keep-Alive Mechanism: Maintains microphone state during active sessions
  3. Unauthorized Audio Detection: Turns off mic when receiving unexpected audio
  4. VAD Bypass Support: Bypasses voice activity detection for PCM subscriptions
  5. Subscription-Based Control: Automatically manages mic based on app needs
  6. 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

  1. Always use debouncing to prevent rapid state changes
  2. Cache subscription state to avoid expensive repeated lookups
  3. Send keep-alive messages to maintain microphone state
  4. Detect unauthorized audio and respond immediately
  5. Bypass VAD when apps need raw PCM data
  6. 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