Skip to content

BrowserAudioOutput

Browser audio output provider that plays audio through the Web Audio API.

Defined in: src/providers/output/BrowserAudioOutput.ts:140

Browser audio output provider that plays audio through the Web Audio API.

Remarks

BrowserAudioOutput adapts the SDK’s existing AudioPlayer to the AudioOutputProvider interface, making speaker playback a first-class pipeline role. It delegates all operations to AudioPlayer:

AudioOutputProvider methodAudioPlayer method
configure(metadata)setMetadata(metadata)
enqueue(chunk)addChunk(chunk)
flush()waitForCompletion()
stop()stop()
pause()pause()
resume()resume()
isPlaying()isPlaying()

Playback callbacks (onPlaybackStart, onPlaybackEnd, onPlaybackError) are wired through to AudioPlayer.setCallbacks().

Data-flow diagram:

OutputQueue ──enqueue()──> BrowserAudioOutput ──addChunk()──> AudioPlayer
                                 |                                |
                           configure()                      setMetadata()
                             flush()                     waitForCompletion()
                              stop()                          stop()

Example

import { BrowserAudioOutput } from 'composite-voice';
import type { AudioChunk, AudioMetadata } from 'composite-voice';

// Create with custom buffer settings
const output = new BrowserAudioOutput({
  minBufferDuration: 150,
  enableSmoothing: true,
});

// Use in a 5-provider pipeline
const voice = new CompositeVoice({
  providers: [
    new MicrophoneInput(),
    new DeepgramSTT({ apiKey: '...' }),
    new AnthropicLLM({ model: 'claude-sonnet-4-20250514', apiKey: '...' }),
    new DeepgramTTS({ apiKey: '...' }),
    output,
  ],
});

// Register playback lifecycle callbacks
output.onPlaybackStart(() => console.log('Speaking...'));
output.onPlaybackEnd(() => console.log('Done speaking'));
output.onPlaybackError((err) => console.error('Playback error:', err));

See

Implements

Constructors

Constructor

new BrowserAudioOutput(config?): BrowserAudioOutput;

Defined in: src/providers/output/BrowserAudioOutput.ts:196

Creates a new BrowserAudioOutput instance.

Parameters

ParameterTypeDescription
configPartial<BrowserAudioOutputConfig>Optional audio output configuration. Missing fields use defaults from DEFAULT_AUDIO_OUTPUT_CONFIG.

Returns

BrowserAudioOutput

Remarks

Instantiates the internal AudioPlayer with the provided configuration. The provider starts in an uninitialized state; call initialize() before use.

Example

// Default configuration
const output = new BrowserAudioOutput();

// Custom buffer settings
const output = new BrowserAudioOutput({
  minBufferDuration: 100,
  sampleRate: 24000,
  enableSmoothing: true,
});

Properties

PropertyModifierTypeDefault valueDescriptionDefined in
rolesreadonlyreadonly ProviderRole[]undefinedPipeline roles covered by this provider. Remarks BrowserAudioOutput is a single-role provider covering only the 'output' slot. Unlike NativeTTS (which covers 'tts' + 'output'), this provider handles playback only and requires a separate TTS provider.src/providers/output/BrowserAudioOutput.ts:152
typereadonlyProviderType'rest'The communication type this provider uses. See ProviderTypesrc/providers/output/BrowserAudioOutput.ts:142

Methods

configure()

configure(metadata): void;

Defined in: src/providers/output/BrowserAudioOutput.ts:292

Configure the output with audio format metadata from the TTS provider.

Parameters

ParameterTypeDescription
metadataAudioMetadataFormat description for the incoming audio stream.

Returns

void

Remarks

Delegates to AudioPlayer.setMetadata(). This should be called before enqueuing chunks so the player knows how to decode and buffer the incoming audio data.

See

Implementation of

AudioOutputProvider.configure


dispose()

dispose(): Promise<void>;

Defined in: src/providers/output/BrowserAudioOutput.ts:230

Dispose of the provider and release all resources.

Returns

Promise<void>

Remarks

Delegates to AudioPlayer.dispose(), which stops playback, closes the AudioContext, and clears callback references. After disposal the instance should not be reused.

Implementation of

AudioOutputProvider.dispose


enqueue()

enqueue(chunk): void;

Defined in: src/providers/output/BrowserAudioOutput.ts:309

Enqueue an audio chunk for playback.

Parameters

ParameterTypeDescription
chunkAudioChunkAudio data to play.

Returns

void

Remarks

Delegates to AudioPlayer.addChunk(). Chunks are buffered and played sequentially. The player applies minimum buffer duration gating before starting playback.

See

Implementation of

AudioOutputProvider.enqueue


flush()

flush(): Promise<void>;

Defined in: src/providers/output/BrowserAudioOutput.ts:323

Wait for all enqueued audio to finish playing.

Returns

Promise<void>

Remarks

Delegates to AudioPlayer.waitForCompletion(). Resolves when the player’s internal queue is drained and the state returns to 'idle'.

See

AudioOutputProvider.flush

Implementation of

AudioOutputProvider.flush


getConfig()

getConfig(): Partial<BrowserAudioOutputConfig>;

Defined in: src/providers/output/BrowserAudioOutput.ts:260

Get a copy of the current audio output configuration.

Returns

Partial<BrowserAudioOutputConfig>

A shallow copy of the current AudioOutputConfig.


initialize()

initialize(): Promise<void>;

Defined in: src/providers/output/BrowserAudioOutput.ts:210

Initialize the provider, making it ready for playback.

Returns

Promise<void>

Remarks

Wires up playback lifecycle callbacks to the underlying AudioPlayer via setCallbacks(). If already initialized, this is a no-op.

Implementation of

AudioOutputProvider.initialize


isPlaying()

isPlaying(): boolean;

Defined in: src/providers/output/BrowserAudioOutput.ts:378

Check whether audio is currently playing.

Returns

boolean

true when audio is actively being played through speakers.

Remarks

Delegates to AudioPlayer.isPlaying(). Returns true only when the player is in the 'playing' state.

See

AudioOutputProvider.isPlaying

Implementation of

AudioOutputProvider.isPlaying


isReady()

isReady(): boolean;

Defined in: src/providers/output/BrowserAudioOutput.ts:251

Check whether the provider has been initialized and is ready for playback.

Returns

boolean

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

Implementation of

AudioOutputProvider.isReady


onPlaybackEnd()

onPlaybackEnd(callback): void;

Defined in: src/providers/output/BrowserAudioOutput.ts:411

Register a callback invoked when all audio has finished playing.

Parameters

ParameterTypeDescription
callback() => voidFunction called when playback ends.

Returns

void

Remarks

The callback is forwarded to AudioPlayer via setCallbacks(). Only one callback can be registered at a time; subsequent calls replace the previous callback.

See

AudioOutputProvider.onPlaybackEnd

Implementation of

AudioOutputProvider.onPlaybackEnd


onPlaybackError()

onPlaybackError(callback): void;

Defined in: src/providers/output/BrowserAudioOutput.ts:428

Register a callback invoked when a playback error occurs.

Parameters

ParameterTypeDescription
callback(error) => voidFunction called with the error.

Returns

void

Remarks

The callback is forwarded to AudioPlayer via setCallbacks(). Only one callback can be registered at a time; subsequent calls replace the previous callback.

See

AudioOutputProvider.onPlaybackError

Implementation of

AudioOutputProvider.onPlaybackError


onPlaybackStart()

onPlaybackStart(callback): void;

Defined in: src/providers/output/BrowserAudioOutput.ts:394

Register a callback invoked when audio playback begins.

Parameters

ParameterTypeDescription
callback() => voidFunction called when playback starts.

Returns

void

Remarks

The callback is forwarded to AudioPlayer via setCallbacks(). Only one callback can be registered at a time; subsequent calls replace the previous callback.

See

AudioOutputProvider.onPlaybackStart

Implementation of

AudioOutputProvider.onPlaybackStart


pause()

pause(): void;

Defined in: src/providers/output/BrowserAudioOutput.ts:350

Temporarily pause playback by suspending the AudioContext.

Returns

void

Remarks

Delegates to AudioPlayer.pause(). Playback can be resumed with resume().

See

AudioOutputProvider.pause

Implementation of

AudioOutputProvider.pause


resume()

resume(): void;

Defined in: src/providers/output/BrowserAudioOutput.ts:363

Resume playback after a pause.

Returns

void

Remarks

Delegates to AudioPlayer.resume().

See

Implementation of

AudioOutputProvider.resume


stop()

stop(): void;

Defined in: src/providers/output/BrowserAudioOutput.ts:337

Stop playback immediately and clear any buffered audio.

Returns

void

Remarks

Delegates to AudioPlayer.stop(). This stops the current AudioBufferSourceNode, clears the queue, and invokes the onPlaybackEnd callback.

See

AudioOutputProvider.stop

Implementation of

AudioOutputProvider.stop


updateConfig()

updateConfig(config): void;

Defined in: src/providers/output/BrowserAudioOutput.ts:273

Update the audio output configuration at runtime.

Parameters

ParameterTypeDescription
configPartial<BrowserAudioOutputConfig>Partial configuration to merge with current settings.

Returns

void

Remarks

Delegates to AudioPlayer.updateConfig(). Some settings (e.g. sampleRate) only take effect on the next AudioContext.

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency