Loading files
442335385This file is pinned to the selected release. Download the original to open it in your design tool.
Files from this revision, including CAD and LFS contents. Git history is not included.
Or in GitHub Desktop, choose File → Clone repository → URL and paste this address.
Public repositories can be cloned without signing in. For pushing, use your ThingAtlas username and a Git access token as the password.
git lfs install git clone https://thingatlas.com/git/-unclaimed/openharness-1322671404.git
Includes Git history, branches, and Git LFS files. Clones the repository’s default branch, regardless of the version shown here.
442335385This file is pinned to the selected release. Download the original to open it in your design tool.
/**
* Process-wide budget for voice PCM buffered ahead of STT. Every device socket may hold up to
* `MAX_PCM` (20 MiB) for one utterance, and `finishVoice` briefly holds a second copy (`Buffer.concat`);
* with nothing above the per-socket cap, "many devices recording at once" was a straight path to the
* OOM-killer taking a whole cluster worker — and every socket on it — instead of one upload failing.
*/
import { env } from '../config/env.js'
let inflightBytes = 0
/** Take `bytes` from the budget. Returns false (and takes nothing) when it would exceed the cap. */
export function reserveVoice(bytes: number): boolean {
if (bytes <= 0) return true
if (inflightBytes + bytes > env.VOICE_INFLIGHT_MAX_BYTES) return false
inflightBytes += bytes
return true
}
/** Give `bytes` back. Clamped at zero so a double release can never grant more than the cap. */
export function releaseVoice(bytes: number): void {
if (bytes <= 0) return
inflightBytes = Math.max(0, inflightBytes - bytes)
}
export function voiceInflightBytes(): number {
return inflightBytes
}