AvaCapoSDK~ AudioManager

Minimal, focused audio graph manager:

  • Owns AudioContext lifecycle.
  • Creates core nodes: Gain (speech/background/stream), Analyser, Convolver.
  • Exposes analyser for metering/lipsync helpers.
  • Lazily loads AudioWorklet for low-latency streaming playback.
  • Provides simple mixer gain and reverb setters.

Usually created internally by higher-level modules (e.g., TalkingAvatar) if needed.

Constructor

new AudioManager(optsopt)

Parameters:
NameTypeAttributesDescription
optsAudioManager.AudioManagerOptions<optional>

Configuration options.

Properties
NameTypeDescription
optsAudioManager.AudioManagerOptions

Current configuration options.

audioCtxAudioContext | null

Audio context (null until initialized).

gainSpeechGainNode | null

Speech gain node.

gainBackgroundGainNode | null

Background/music gain node.

gainStreamGainNode | null

Streaming gain node.

analyserAnalyserNode | null

Analyser for metering/lipsync.

convolverConvolverNode | null

Reverb convolver.

speechBufferSourceAudioBufferSourceNode | null

Last created speech buffer source.

backgroundBufferSourceAudioBufferSourceNode | null

Last created background buffer source.

workletLoadedboolean

Whether the worklet is loaded.

streamNodeAudioWorkletNode | null

Worklet node for streaming.

Members

(static, constant) AUDIO_DEFAULTS :AudioManager.AudioManagerOptions

Default options of AudioManager.

{
  sampleRate: null,
  mixer: { speech: 1, background: 0 },
  analyser: { fftSize: 256, smoothing: 0.1, minDb: -70, maxDb: -10 },
  reverb: { ir: "dry", normalize: false },
  workletUrl: null
}

Methods

createBackgroundSource() → {AudioBufferSourceNode}

Create a one-shot BufferSource for background playback.

Returns:
Type: 
AudioBufferSourceNode

createSpeechSource() → {AudioBufferSourceNode}

Create a one-shot BufferSource for speech playback.

Returns:
Type: 
AudioBufferSourceNode

createStreamNode() → {AudioWorkletNode}

Create a fresh AudioWorkletNode for streaming playback. Caller wires up message handlers on node.port.

Throws:

If worklet is not loaded (call ensureWorkletLoaded() first).

Type
Error
Returns:
Type: 
AudioWorkletNode

(async) dispose() → {Promise.<void>}

Dispose all audio resources. Closes context and releases nodes. Safe to call multiple times (idempotent).

Returns:
Type: 
Promise.<void>

(async) ensureWorkletLoaded() → {Promise.<void>}

Ensure the AudioWorklet module is loaded once per AudioContext.

Throws:

If AudioContext is unavailable/closed, URL cannot be resolved, or loading times out.

Type
Error
Returns:
Type: 
Promise.<void>

getAnalyserNode() → {AnalyserNode}

Returns the analyser node for metering.

Returns:
Type: 
AnalyserNode

rebuild(sampleRate) → {void}

Rebuild the entire graph with a new sample rate.

Parameters:
NameTypeDescription
sampleRatenumber

Target sample rate in Hz.

Returns:
Type: 
void

(async) resumeIfNeeded() → {Promise.<void>}

Resume the AudioContext if suspended/interrupted (autoplay policies). No-op if context is absent.

Returns:
Type: 
Promise.<void>

setMixerGain(speechopt, backgroundopt, fadeSecsopt) → {void}

Set speech/background gains with optional exponential fade.

Parameters:
NameTypeAttributesDefaultDescription
speechnumber | null<optional>
null

Target speech gain (linear, typically 0..1). Pass null to keep current.

backgroundnumber | null<optional>
null

Target background gain (linear, typically 0..1). Pass null to keep current.

fadeSecsnumber<optional>
0

Exponential fade duration in seconds (0 = instant).

Returns:
Type: 
void

(async) setReverb(input, optsopt) → {Promise.<void>}

Set the impulse response buffer used by the internal ConvolverNode.

Passing a non-null AudioBuffer enables reverb with that IR. Passing null clears the buffer and effectively bypasses the convolver, which is the cheapest option CPU-wise. behavior (keep the convolver active but with no tail), create a Dirac buffer yourself and pass it here.

Parameters:
NameTypeAttributesDescription
inputstring | ArrayBuffer | AudioBuffer | null

Allowed strings: "off", "dry".

optsAudioManager.ReverbSetOptions<optional>
Throws:

On fetch/decode failures (when input is URL/ArrayBuffer).

Type
Error
Returns:
Type: 
Promise.<void>
Examples
// Enable reverb:
audio.setReverb(irBuffer);
// Bypass (no reverb, lowest CPU cost):
audio.setReverb(null);
// Optional: emulate a dry impulse (no tail, convolver stays active):
const sr = audio.audioCtx.sampleRate;
const dry = audio.audioCtx.createBuffer(2, sr, sr);
dry.getChannelData(0)[0] = 1.0;
dry.getChannelData(1)[0] = 1.0;
audio.setReverb(dry);

stopBackground() → {void}

Stop current background audio if playing.

Returns:
Type: 
void

Type Definitions

AudioAnalyserOptions

Analyser settings for metering/lip-sync.

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
fftSizenumber<optional>
256

FFT size (power of two).

smoothingnumber<optional>
0.1

Smoothing factor in [0..1].

minDbnumber<optional>
-70

Minimum decibels.

maxDbnumber<optional>
-10

Maximum decibels.

AudioManagerOptions

Audio engine options for AudioManager.

Type:
  • Object
Properties
NameTypeAttributesDescription
sampleRatenumber | null<optional>

Optional AudioContext sampleRate hint.

mixerAudioManager.AudioMixerOptions<optional>

Mixer gains for speech/background.

analyserAudioManager.AudioAnalyserOptions<optional>

Analyser configuration.

reverbAudioManager.AudioReverbOptions<optional>

Reverb/convolver configuration.

workletUrlstring | null<optional>

URL to the AudioWorklet module; if omitted, a resolver is used.

AudioMixerOptions

Mixer (linear gains). Typical range: 0..1 (but not clamped).

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
speechnumber<optional>
1

Gain for speech path.

backgroundnumber<optional>
0

Gain for background/music path.

AudioReverbOptions

Reverb (convolver) settings. ir accepted values:

  • 'dry': use a unit impulse (no tail; convolver remains active)
  • 'off': disable/bypass convolver (lowest CPU usage)
  • null: same as 'off'
  • string: URL to an impulse response file (fetched and decoded)
  • ArrayBuffer | AudioBuffer: preloaded IR data
Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
irstring | null | ArrayBuffer | AudioBuffer<optional>
"dry"

Impulse response source. Allowed strings: "dry", "off".

normalizeboolean<optional>
false

Convolver normalization flag.

PlayBackgroundOptions

Options for AudioManager#playBackgroundFromUrl.

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
loopboolean<optional>
true

Loop playback.

ratenumber<optional>
1.0

playbackRate multiplier.

ReverbSetOptions

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
normalizeboolean<optional>
false

Convolver normalization flag.