@audio/encode-aac

中文文档
1.2.1发布于 2026/09/27MIT AND FDK-AACTypeScriptES Module零依赖近 30 天下载 2776

Encode PCM audio samples to AAC (ADTS): WebCodecs, else the Fraunhofer FDK encoder (WASM)

原始使用文档

@audio/encode-aac

Encode PCM audio samples to AAC (ADTS) format, in browsers and Node.
Where the browser's WebCodecs AudioEncoder supports the configuration (Chromium 94+, Safari 16+) it encodes there: zero bundle cost, hardware-accelerated. Everywhere else (Node, Firefox) it runs the Fraunhofer FDK AAC encoder (v2.0.3) compiled to WebAssembly, loaded on first use.

npm install @audio/encode-aac

import aac from '@audio/encode-aac';

const encoder = await aac({ sampleRate: 44100, channels: 2, bitrate: 128 });
const a = await encoder.encode(chunk1); // → Uint8Array (ADTS frames)
const b = await encoder.encode(chunk2);
const c = await encoder.flush();        // → Uint8Array (remaining frames); frees the encoder
// complete ADTS AAC = concat(a, b, c)

Options

OptionDefaultDescription
sampleRate—Input sample rate in Hz (required)
channels11 or 2; FDK also 3–6 and 8 (WAV channel order)
bitrate128Target bitrate in kbps
profile'lc''lc' AAC-LC, 'he' HE-AAC (SBR), 'hev2' HE-AACv2 (SBR + PS, stereo only)

The encoder reports priming (its delay in samples: FDK 2048 for AAC-LC) and frameLength (1024; 2048 for HE-AAC), which a container needs for gapless playback. @audio/encode-mp4 uses them.

Output is raw ADTS-framed AAC: each chunk is a sequence of whole ADTS frames, playable as .aac. HE-AAC signals SBR implicitly (an LC header at the core rate), as ADTS must.

License

MIT. The FDK encoder inside (src/fdk.wasm.js) is the Fraunhofer FDK AAC Codec Library, distributed under its own license (LICENSE.fdk-aac): free to redistribute with that notice, and granting no patent license. AAC is covered by patents; commercial distributors may need a license from the patent pool (Via LA).

ॐ

版本与发布记录

@audio/encode-aac 共发布 7 个版本,首次发布于 2026/06/23;过去 12 个月发布了 7 个版本。

版本发布日期距今
1.2.1latest2026/09/271 个月前
1.2.02026/09/261 个月前
1.1.32026/08/292 个月前
1.1.22026/07/113 个月前
1.1.12026/07/113 个月前
1.1.02026/07/103 个月前

关于 @audio/encode-aac 的常见问题

@audio/encode-aac 是什么?

Encode PCM audio samples to AAC (ADTS): WebCodecs, else the Fraunhofer FDK encoder (WASM)

如何安装 @audio/encode-aac?

在项目目录运行 npm install @audio/encode-aac,或使用 pnpm add / yarn add / bun add。

@audio/encode-aac 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@audio/encode-aac 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@audio/encode-aac 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@audio/encode-aac 可以商用吗?

@audio/encode-aac 使用 MIT AND FDK-AAC 许可。声明的许可为 MIT AND FDK-AAC,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@audio/encode-aac 的下载量有多少?

根据 npm 官方下载统计,@audio/encode-aac 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,776 次,日均约 93 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@audio/encode-aac 还在维护吗?

最新版本 1.2.1 发布于 2026/09/27(1 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/06/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。