moeru-ai/airi · error · Error
AudioContext or worklets not ready
Error message
AudioContext or worklets not ready
What it means
createResamplingWorkletNode is stricter than the other factories: it needs the AudioContext ready AND workletLoaded true, because AudioWorkletNode(context, 'resampling-processor', ...) only works after both addModule calls in loadWorklets() succeeded. If either condition fails it throws this error.
Solutions
- Await initializeAudioContext() — it loads both worklet modules and sets workletLoaded — before creating resampling nodes
- If init threw 'Worklet loading failed', fix that first (URL, MIME type, CSP); this error is the downstream symptom
- Feature-detect AudioWorklet support and skip the resampling path where unavailable
Example fix
// before
const node = createResamplingWorkletNode(source) // Error: AudioContext or worklets not ready
// after
if (typeof AudioWorkletNode === 'undefined') throw new Error('AudioWorklet unsupported')
await initializeAudioContext(48000) // loads processor + libsamplerate worklets
const node = createResamplingWorkletNode(source) Defensive patterns
Strategy: validation
Validate before calling
if (typeof AudioWorkletNode === 'undefined')
throw new Error('AudioWorklet unsupported in this environment')
await initializeAudioContext(48000) // loads both worklet modules and sets workletLoaded
const node = createResamplingWorkletNode(source) Try / catch
try {
const node = createResamplingWorkletNode(source)
}
catch (err) {
if (err instanceof Error && err.message === 'AudioContext or worklets not ready') {
await initializeAudioContext(48000) // retry the gate that sets workletLoaded
return createResamplingWorkletNode(source)
}
throw err
} Prevention
- Treat initializeAudioContext as the only entry to worklet-based pipelines
- Propagate worklet load failures instead of continuing to build nodes
- Feature-detect AudioWorklet before offering resampling features
When it happens
Trigger: Calling createResamplingWorkletNode(inputNode) before initializeAudioContext() resolves (worklets load inside it), or after loadWorklets failed — the wrapped 'Worklet loading failed' error was caught upstream and this factory is still used.
Common situations: Speech/mic capture code creating a 16 kHz resampling pipe before the audio bootstrap completes; environments without AudioWorklet support; a previous worklet load failure (CSP, 404) left workletLoaded false while callers ignored the init error.
Related errors
- Worklet loading failed
- AudioContext not initialized
- Camera or Renderer initialisation failure!
- Cannot declare permissions for unknown plugin
- Cannot grant permissions to unknown plugin
AI-assisted analysis of moeru-ai/airi@677329427f (2026-08-18).
Data as JSON: /api/errors/741949077d946fd3.
Report an issue: GitHub.
Appendix: 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 677329427f)