Skip to content

BufferInput

Server-side audio input provider that accepts pushed audio buffers.

Defined in: src/providers/input/BufferInput.ts:117

Server-side audio input provider that accepts pushed audio buffers.

Remarks

BufferInput allows server-side applications to feed audio data into the CompositeVoice pipeline without any browser dependencies. The application pushes raw audio via push(), and BufferInput wraps each buffer into an AudioChunk with a timestamp and sequence number before delivering it to the registered callback.

The audio format is declared up-front in the constructor via AudioMetadata, enabling the pipeline to auto-configure STT encoding/sample-rate settings without needing to sniff audio frames.

Data-flow diagram:

app.push(data) ──> BufferInput ──callback(chunk)──> InputQueue ──> STT
                       |
                 active=true?
                   yes: emit
                   no:  drop

Example

import { BufferInput } from 'composite-voice';
import { createReadStream } from 'node:fs';

const input = new BufferInput({
  sampleRate: 16000,
  encoding: 'linear16',
  channels: 1,
  bitDepth: 16,
});

await input.initialize();
input.onAudio((chunk) => {
  console.log(`Received ${chunk.data.byteLength} bytes, seq=${chunk.sequence}`);
});
input.start();

// Stream audio from a file
const stream = createReadStream('audio.raw', { highWaterMark: 4096 });
stream.on('data', (buf: Buffer) => input.push(buf.buffer));

See

Implements

Constructors

Constructor

new BufferInput(metadata): BufferInput;

Defined in: src/providers/input/BufferInput.ts:176

Creates a new BufferInput instance.

Parameters

ParameterTypeDescription
metadataAudioMetadataFormat description for the audio that will be pushed. Must include at least sampleRate, encoding, and channels.

Returns

BufferInput

Remarks

The metadata parameter declares the audio format that will be pushed via push(). This metadata is returned by getMetadata() and used by the pipeline to auto-configure the downstream STT provider.

Example

const input = new BufferInput({
  sampleRate: 16000,
  encoding: 'linear16',
  channels: 1,
  bitDepth: 16,
});

Properties

PropertyModifierTypeDefault valueDescriptionDefined in
rolesreadonlyreadonly ProviderRole[]undefinedPipeline roles covered by this provider. Remarks BufferInput is a single-role provider covering only the 'input' slot. It requires a separate STT provider for the 'stt' role.src/providers/input/BufferInput.ts:134
typereadonlyProviderType'rest'Communication type for this provider. Remarks BufferInput uses 'rest' because it does not maintain a persistent connection — audio is pushed imperatively by the application.src/providers/input/BufferInput.ts:125

Methods

dispose()

dispose(): Promise<void>;

Defined in: src/providers/input/BufferInput.ts:201

Dispose of the provider and release all resources.

Returns

Promise<void>

Remarks

Stops accepting audio, clears the callback reference, and resets the sequence counter. After disposal the instance should not be reused.

Implementation of

AudioInputProvider.dispose


getMetadata()

getMetadata(): AudioMetadata;

Defined in: src/providers/input/BufferInput.ts:306

Get the audio format metadata for the audio being pushed.

Returns

AudioMetadata

A copy of the AudioMetadata provided to the constructor.

Remarks

Returns the metadata provided at construction time. Used by the pipeline to auto-configure STT encoding, sample rate, and channel settings via configureSTTFromMetadata().

Implementation of

AudioInputProvider.getMetadata


initialize()

initialize(): Promise<void>;

Defined in: src/providers/input/BufferInput.ts:189

Initialize the provider, making it ready to accept audio.

Returns

Promise<void>

Remarks

A no-op beyond setting the initialized flag, since BufferInput has no external resources to acquire. If already initialized, this is a no-op.

Implementation of

AudioInputProvider.initialize


isActive()

isActive(): boolean;

Defined in: src/providers/input/BufferInput.ts:277

Check whether the provider is actively emitting audio.

Returns

boolean

true when started and not paused.

Implementation of

AudioInputProvider.isActive


isReady()

isReady(): boolean;

Defined in: src/providers/input/BufferInput.ts:216

Check whether the provider has been initialized.

Returns

boolean

true when initialize has completed and dispose has not yet been called.

Implementation of

AudioInputProvider.isReady


onAudio()

onAudio(callback): void;

Defined in: src/providers/input/BufferInput.ts:292

Register a callback to receive audio chunks.

Parameters

ParameterTypeDescription
callback(chunk) => voidFunction invoked with each AudioChunk when audio is pushed and the provider is active.

Returns

void

Remarks

Only one callback can be registered at a time; subsequent calls replace the previous callback. Must be called before start().

Implementation of

AudioInputProvider.onAudio


pause()

pause(): void;

Defined in: src/providers/input/BufferInput.ts:255

Temporarily pause audio emission without stopping the provider.

Returns

void

Remarks

Audio pushed while paused is silently dropped. Resume with resume().

Implementation of

AudioInputProvider.pause


push()

push(data): void;

Defined in: src/providers/input/BufferInput.ts:334

Push raw audio data into the pipeline.

Parameters

ParameterTypeDescription
dataArrayBufferRaw audio bytes matching the format declared in the constructor’s AudioMetadata.

Returns

void

Remarks

Wraps the raw ArrayBuffer into an AudioChunk with a timestamp and monotonically increasing sequence number, then delivers it to the registered callback. If the provider is not active (not started, stopped, or paused), the data is silently dropped.

Example

// Push PCM audio from a Node.js Buffer
const pcmBuffer = Buffer.alloc(3200); // 100ms of 16kHz 16-bit mono
input.push(pcmBuffer.buffer);

// Push from a WebSocket message
ws.on('message', (data: ArrayBuffer) => input.push(data));

resume()

resume(): void;

Defined in: src/providers/input/BufferInput.ts:266

Resume audio emission after a pause.

Returns

void

See

pause

Implementation of

AudioInputProvider.resume


start()

start(): void;

Defined in: src/providers/input/BufferInput.ts:231

Start accepting and emitting audio chunks.

Returns

void

Remarks

After calling start(), audio pushed via push() will be delivered to the callback registered with onAudio(). Must be called after initialize().

Implementation of

AudioInputProvider.start


stop()

stop(): void;

Defined in: src/providers/input/BufferInput.ts:243

Stop accepting audio and cease emitting chunks.

Returns

void

Remarks

Audio pushed after stop() is silently dropped. The provider can be restarted with start().

Implementation of

AudioInputProvider.stop

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency