/** * Control message the main thread posts to the worklet to ask it to emit any * partially-filled buffer immediately (rather than waiting for it to reach the * chunk size) and acknowledge. Used to flush the trailing audio before capture * is torn down so the final spoken words are not dropped. */ export declare const PCM_FLUSH_REQUEST = "vscode-pcm-flush"; /** Control message the worklet posts back after emitting its buffered tail. */ export declare const PCM_FLUSH_ACK = "vscode-pcm-flushed"; /** * Subset of {@link MessagePort} used by {@link wirePcmCapturePort}: it posts * flush requests and receives chunk/ack messages. */ export type IPcmCapturePort = Pick; /** Timer functions used by {@link wirePcmCapturePort} (satisfied by `window`). */ export type IPcmCaptureTimers = Pick; /** * Wire the main-thread side of the capture worklet's message port: route audio * chunks to `onChunk`, and expose a `flush` that asks the worklet to emit its * partial trailing buffer and resolves once the acknowledgment arrives (or after * a timeout if the audio thread never responds). */ export declare function wirePcmCapturePort(port: IPcmCapturePort, timers: IPcmCaptureTimers, onChunk: (samples: Float32Array) => void): { flush(): Promise; }; /** * A PCM capture worklet node together with a `flush` that drains its * partially-filled trailing buffer. */ export interface IPcmCaptureNode { /** * The capture node. Not connected to the audio graph; the caller is * responsible for connecting it (typically source -> node -> destination) * and for disposing it via `node.disconnect()` and clearing * `node.port.onmessage`. */ readonly node: AudioWorkletNode; /** * Ask the worklet to emit any audio buffered so far (a partial chunk that * has not yet reached the chunk size) and resolve once it has. The buffered * samples are delivered through the same `onChunk` callback before this * resolves, so callers can flush the trailing audio to their backend before * stopping capture. Resolves after a short timeout even if the audio thread * never acknowledges (e.g. the context is already closing). */ flush(): Promise; } /** * Creates an {@link AudioWorkletNode} that captures mono PCM from `context` in * fixed-size chunks, invoking `onChunk` on the main thread for every chunk. The * worklet module is loaded from a blob URL, which the renderer's `script-src` * CSP allows (worklet scripts fall back to `script-src`). */ export declare function createPcmCaptureNode(window: Window & typeof globalThis, context: AudioContext, chunkSize: number, onChunk: (samples: Float32Array) => void): Promise;