{"record":{"id":"b5101424d7b0dbcb","repo":"toeverything/AFFiNE","slug":"audioencoder-is-not-available-in-this-environment","errorCode":null,"errorMessage":"AudioEncoder is not available in this environment","messagePattern":"AudioEncoder is not available in this environment","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/frontend/core/src/utils/opus-encoding.ts","lineNumber":134,"sourceCode":"  for (let channel = 0; channel < numberOfChannels; channel++) {\n    const channelData = audioBuffer.getChannelData(channel);\n    for (let i = 0; i < sampleCount; i++) {\n      audioData[i * numberOfChannels + channel] = channelData[startSample + i];\n    }\n  }\n\n  return audioData;\n}\n\n/**\n * Creates and configures an Opus encoder with the given settings\n */\nexport function createOpusEncoder(config: AudioEncodingConfig): {\n  encoder: AudioEncoder;\n  encodedChunks: EncodedAudioChunk[];\n} {\n  if (typeof AudioEncoder === 'undefined') {\n    throw new Error('AudioEncoder is not available in this environment');\n  }\n\n  const encodedChunks: EncodedAudioChunk[] = [];\n  const encoder = new AudioEncoder({\n    output: chunk => {\n      encodedChunks.push(chunk);\n    },\n    error: err => {\n      throw new Error(`Encoding error: ${err}`);\n    },\n  });\n\n  encoder.configure({\n    codec: 'opus',\n    sampleRate: config.sampleRate,\n    numberOfChannels: config.numberOfChannels,\n    bitrate: config.bitrate ?? DEFAULT_BITRATE,\n  });","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/frontend/core/src/utils/opus-encoding.ts#L116-L152","documentation":"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.","triggerScenarios":"Thrown by createOpusEncoder when the WebCodecs AudioEncoder global is undefined, i.e. the browser or runtime does not implement the WebCodecs audio encoding API.","commonSituations":"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.","solutions":["Use a browser/environment that supports AudioEncoder (recent Chromium).","Fall back to a different audio encoding path if available."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}