/** * Who is being transcribed right now. At most `max` people at once (settings voice.maxSpeakers); * someone who starts while the limit is reached is not heard until their next start after the * others free a place. */ export class SpeakerGate { private active = new Set(); constructor(private max: number) {} /** Discord says `id` started speaking. True if their audio goes to the STT. */ start(id: string): boolean { if (this.active.has(id)) return true; if (this.active.size >= this.max) return false; this.active.add(id); return true; } /** Discord says `id` stopped (or left). True if they were being transcribed. */ end(id: string): boolean { return this.active.delete(id); } isActive(id: string): boolean { return this.active.has(id); } get count(): number { return this.active.size; } clear(): void { this.active.clear(); } }