observeInputLevel (voice/input-level.ts)

airi · packages/stage-ui/src/libs/voice/input-level.ts · typescript · MIT
voice, tag:knn-classified

Observes microphone input level and reports RMS‑based volume in real time.

// Source: https://github.com/moeru-ai/airi | License: MIT | Copyright 2024-PRESENT Neko Ayaka
// Provided via justclaw.it.com; keep this notice with the code.
import type { AudioInput, Observer } from '@proj-airi/pipelines-audio'

import { observe } from '@proj-airi/pipelines-audio'

/** One level per window gives a 20 Hz meter, which is smooth enough for a volume halo. */
const LEVEL_WINDOW_MS = 50
/** The meter shows signal from -60 dBFS (level 0) to full scale (level 1). Quieter input reads as silence. */
const LEVEL_FLOOR_DB = -60

/**
 * Publishes the microphone level until `signal` aborts.
 *
 * The observation subscribes to `input`, so it keeps the microphone open. Run it only while a control already captures audio.
 * Each level is the root mean square of all channels in one windo

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key