moeru-ai/airi · error

AudioContext or worklets not ready

Error message

AudioContext or worklets not ready

What it means

createResamplingWorkletNode applies a stricter guard than the other factories: it requires context AND isReady AND workletLoaded. The resampling worklet node depends on the libsamplerate worklet module, so even if the AudioContext is ready, a failed/skipped loadWorklets leaves workletLoaded false and this function refuses to construct the node.

Source

Thrown at packages/audio/src/audio-context/index.ts:227

  if (context && context.state === 'running') {
    await context.suspend()
    notifyListeners()
  }
}

export async function resumeAudioContext() {
  if (context && context.state === 'suspended') {
    await context.resume()
    notifyListeners()
  }
}

export function createResamplingWorkletNode(
  inputNode: AudioNode,
  options: WorkletOptions = {},
): AudioWorkletNode {
  if (!context || !isReady || !workletLoaded) {
    throw new Error('AudioContext or worklets not ready')
  }

  const workletOptions = {
    inputSampleRate: sampleRate,
    outputSampleRate: 16000,
    channels: 1,
    converterType: 2, // SRC_SINC_MEDIUM_QUALITY
    bufferSize: 4096,
    ...options,
  }

  const workletNode = new AudioWorkletNode(context, 'resampling-processor', {
    numberOfInputs: 1,
    numberOfOutputs: 1,
    channelCount: workletOptions.channels,
    processorOptions: workletOptions,
  })

View on GitHub (pinned to 27111382b4)

Solutions

  1. Ensure loadWorklets() completed (no error 190) before constructing resampling nodes.
  2. Subscribe to a readiness state that includes workletLoaded, not just isReady.
  3. Degrade to a non-worklet resampling path when workletLoaded is false.

Example fix

// before
const node = createResamplingWorkletNode(inputNode)

// after
await initializeAudioContext()
if (!workletLoaded) {
  throw new Error('Resampling requires AudioWorklet support; ensure loadWorklets succeeded')
}
const node = createResamplingWorkletNode(inputNode)
Defensive patterns

Strategy: validation

Validate before calling

if (!context || !isReady || !workletLoaded) {
  throw new Error('Resampling node requires AudioContext ready AND worklets loaded')
}

Type guard

function isWorkletReady(): boolean {
  return !!context && isReady && workletLoaded
}

Try / catch

try {
  return createResamplingWorkletNode(inputNode, options)
}
catch (err) {
  if (/worklets not ready/i.test((err as Error).message)) {
    // fall back to a ScriptProcessorNode or non-resampling path
    return createFallbackResampler(inputNode, options)
  }
  throw err
}

Prevention

When it happens

Trigger: initializeAudioContext succeeded the context but loadWorklets failed (error 190) so workletLoaded stayed false; calling before initializeAudioContext completes; the worklet loaded flag was reset after teardown.

Common situations: Audio init partially succeeded (context up, worklets failed) and the caller assumes full readiness; insecure context allows a context but not AudioWorklet; bundler emitted the context init but not the worklet files.

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/741949077d946fd3. Report an issue: GitHub.