toeverything/AFFiNE · error · Error

AudioEncoder is not available in this environment

Error message

AudioEncoder is not available in this environment

What it means

createOpusEncoder throws when the WebCodecs AudioEncoder global is undefined, meaning the current environment (browser or context) lacks WebCodecs audio encoding support required for Opus transcription preprocessing.

Source

Thrown at packages/frontend/core/src/utils/opus-encoding.ts:134

  for (let channel = 0; channel < numberOfChannels; channel++) {
    const channelData = audioBuffer.getChannelData(channel);
    for (let i = 0; i < sampleCount; i++) {
      audioData[i * numberOfChannels + channel] = channelData[startSample + i];
    }
  }

  return audioData;
}

/**
 * Creates and configures an Opus encoder with the given settings
 */
export function createOpusEncoder(config: AudioEncodingConfig): {
  encoder: AudioEncoder;
  encodedChunks: EncodedAudioChunk[];
} {
  if (typeof AudioEncoder === 'undefined') {
    throw new Error('AudioEncoder is not available in this environment');
  }

  const encodedChunks: EncodedAudioChunk[] = [];
  const encoder = new AudioEncoder({
    output: chunk => {
      encodedChunks.push(chunk);
    },
    error: err => {
      throw new Error(`Encoding error: ${err}`);
    },
  });

  encoder.configure({
    codec: 'opus',
    sampleRate: config.sampleRate,
    numberOfChannels: config.numberOfChannels,
    bitrate: config.bitrate ?? DEFAULT_BITRATE,
  });

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Use a browser/environment that supports AudioEncoder (recent Chromium).
  2. Fall back to a different audio encoding path if available.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown by createOpusEncoder when the WebCodecs AudioEncoder global is undefined, i.e. the browser or runtime does not implement the WebCodecs audio encoding API.

Common situations: Audio recording with Opus encoding is started in an unsupported browser such as Firefox or Safari. Use a Chromium-based browser or the desktop app to enable this feature.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/b5101424d7b0dbcb. Report an issue: GitHub.