iflytek/astron-agent · error

录音错误:

Error message

录音错误:${checkMsg}

What it means

Recorder-Core's stop() runs This.envCheck for mock recordings (isMock=true) and prepends any returned environment-compat message to '录音错误:'. When a mock environment (mockEnvInfo, e.g. envName:'mock', canProcess:false) reports it cannot process audio, stop aborts with this composed error.

Solutions

  1. Don't use isMock in a real browser — use the normal recorder; mock is only for custom/native environments.
  2. Provide mockEnvInfo with canProcess:true and a working envCheck implementation when using mocks.
  3. Register the platform environment (envCheck shim) before constructing the mock recorder.
  4. Route the error to a fallback: skip recording or surface a clear 'environment not supported' message to users.
  5. In unit tests, assert envCheck passes before exercising stop().

Example fix

// before
var rec = Recorder({ type: 'wav', isMock: true }); // no mockEnvInfo
rec.stop(cb); // '录音错误:mock canProcess=false'

// after
var rec = Recorder({
  type: 'wav',
  isMock: true,
  mockEnvInfo: { envName: 'myNative', canProcess: true, envCheck: function() { return myBridgeReady ? '' : 'bridge not ready'; } }
});
Defensive patterns

Strategy: fallback

Validate before calling

if (rec.isMock && rec.mockEnvInfo && typeof rec.mockEnvInfo.envCheck === 'function') {
  const msg = rec.mockEnvInfo.envCheck(rec.mockEnvInfo);
  if (msg) { showToast('Environment unsupported: ' + msg); return; }
}

Type guard

function mockEnvUsable(rec) { return !rec.isMock || (!!rec.mockEnvInfo && rec.mockEnvInfo.canProcess === true); }

Try / catch

try { rec.stop(cb); } catch (e) {
  if (String(e).includes('录音错误')) fallbackToTextCapture();
}

Prevention

When it happens

Trigger: rec.stop() on a recorder constructed with isMock:true whose mockEnvInfo either isn't provided (defaults to {envName:'mock', canProcess:false}) or whose envCheck returns a non-empty incompatibility message.

Common situations: Testing/recording in non-browser environments (SSR, WeChat/native webview without proper env registration, jsdom in unit tests); mock recorder created without passing mockEnvInfo; canProcess left false because the platform shim (e.g. native recorder bridge) wasn't installed.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/ad86b14135b11c0c. Report an issue: GitHub.

Appendix: source

Thrown at console/frontend/src/utils/record/recorder-core.js:1401

        err('未采集到录音');
        return;
      }
      if (!This.buffers[0]) {
        err('音频buffers被释放');
        return;
      }
      if (!This[set.type]) {
        err('未加载' + set.type + '编码器');
        return;
      }

      //环境配置检查,此处仅针对mock调用,因为open已经检查过了
      if (This.isMock) {
        var checkMsg = This.envCheck(
          This.mockEnvInfo || { envName: 'mock', canProcess: false }
        ); //没有提供环境信息的mock时没有onProcess回调
        if (checkMsg) {
          err('录音错误:' + checkMsg);
          return;
        }
      }

      //此类型有边录边转码(Worker)支持
      var engineCtx = This.engineCtx;
      if (This[set.type + '_complete'] && engineCtx) {
        var duration = Math.round(
          (engineCtx.pcmSize / set[sampleRateTxt]) * 1000
        ); //采用后的数据长度和buffers的长度可能微小的不一致,是采样率连续转换的精度问题

        t1 = Date.now();
        This[set.type + '_complete'](
          engineCtx,
          function (blob) {
            ok(blob, duration);
          },
          err

View on GitHub (pinned to 5e758547a8)