@desert-ant-labs/ear

中文文档
4.3.0发布于 2026/11/06SEE LICENSE IN LICENSE.mdTypeScriptES Module近 30 天下载 1.7万

On-device spoken language identification for JavaScript: name the language of a recording before you transcribe it. Runs in the browser (WebAssembly + LiteRT.js) and server-side in Node (native), from one import.

原始使用文档
文档目录5 节
  1. Use
  2. Branch on isReliable , not on confidence
  3. What it listens to
  4. Limits
  5. License

@desert-ant-labs/ear

On-device spoken language identification for JavaScript. Takes a recording and names the language it is in, so an app can pick the right recognizer before it starts transcribing. Everything runs locally, so the audio never leaves the device or browser.

Two entries share one Ear API:

  • @desert-ant-labs/ear (default): a WebAssembly pipeline with LiteRT.js inference (XNNPACK-accelerated CPU by default, optional WebGPU), for the browser. It has no native dependencies, so a single import builds cleanly for every target of a multi-target bundler (Next.js, Remix, SvelteKit, Nuxt), including the browser bundle and the Client-Component SSR pass those frameworks render in Node. It is safe to import during server-side rendering, but LiteRT.js needs a browser (or Web Worker) to initialize, so Ear.load() runs inference only in the browser; calling it in plain Node throws an actionable error pointing you to /native.
  • @desert-ant-labs/ear/native: a prebuilt native core (LiteRT on Linux, Core ML on macOS), for server-side inference in Node. No @litertjs/core, no build tools, no flags. Import it from server-only code (API routes, server actions, plain Node scripts). Do not import it from a component that also renders in the browser.
# Browser (default entry):
npm i @desert-ant-labs/ear @litertjs/core

# Server-side inference in Node (/native entry) needs no extra install:
npm i @desert-ant-labs/ear

Use

import { Ear } from "@desert-ant-labs/ear";          // browser
// import { Ear } from "@desert-ant-labs/ear/native"; // Node

const ear = await Ear.load();                        // downloads once, then cached
const detection = await ear.identify(samples, 16000);

detection.language      // "pt"
detection.confidence    // 0.98
detection.isReliable    // true

ear.dispose();

samples is mono Float32Array at any rate; audio is resampled, and 16 kHz avoids the conversion.

Branch on isReliable, not on confidence

if (detection.isReliable) {
  transcribeWith(detection.language);
} else {
  askTheUser();            // or fall back to a general recognizer
}

isReliable is false when the top two candidates are too close to separate, and false for the Nordic languages, which the model confuses with each other confidently rather than uncertainly - so their probability does not reveal the problem and a threshold on confidence cannot catch it. The flag is decided in the model and crosses the boundary as a number, so every SDK reads the same verdict.

The threshold behind it was set by sweeping it against 162 recordings: of the answers above it, 98.5% route correctly, and on files in a language the primary recognizer supports, 100% do.

What it listens to

A file handed to a transcriber is not speech end to end, so Ear does not listen to it end to end either. It ranks candidate windows by how much of their loudness varies at syllable rate - speech rises and falls three to six times a second and has gaps between words, music sustains, silence does not vary at all

  • and listens to the three most speech-like.

Pass windows to change how many:

await ear.identify(samples, 16000, { windows: 5 });

Limits

  • Speech mixed under louder music is read correctly about 60% of the time. Choosing better windows does not help; the model cannot read it.
  • Nordic languages are not distinguished reliably, and isReliable is false for all of them rather than reporting one confidently.
  • Recordings shorter than thirty seconds get a single window, so there is nothing to average and the answer is less certain than the number suggests.
  • Multilingual recordings are reported as whichever language the chosen windows contain, not as a mixture.

License

Desert Ant Labs Source-Available License. Free for most apps, and a commercial license is required at scale. Full terms are at the link. Licensing: [email protected].

Third-party notices for the SDK: THIRD_PARTY_NOTICES.md.

Third-party notices for the weights: THIRD_PARTY_NOTICES.md.

版本与发布记录

@desert-ant-labs/ear 共发布 14 个版本,首次发布于 2026/08/28;过去 12 个月发布了 14 个版本。

版本发布日期距今
4.3.0latest2026/11/066 天前
4.2.32026/10/3112 天前
4.2.22026/10/3112 天前
4.2.12026/10/2815 天前
4.2.02026/10/2716 天前
4.1.02026/10/2023 天前

关于 @desert-ant-labs/ear 的常见问题

@desert-ant-labs/ear 是什么?

On-device spoken language identification for JavaScript: name the language of a recording before you transcribe it. Runs in the browser (WebAssembly + LiteRT.js) and server-side in Node (native), from one import.

如何安装 @desert-ant-labs/ear?

在项目目录运行 npm install @desert-ant-labs/ear,或使用 pnpm add / yarn add / bun add。

@desert-ant-labs/ear 支持 TypeScript 吗?

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

@desert-ant-labs/ear 支持 ESM 还是 CommonJS?

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

@desert-ant-labs/ear 可以商用吗?

@desert-ant-labs/ear 使用 SEE LICENSE IN LICENSE.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@desert-ant-labs/ear 的下载量有多少?

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

@desert-ant-labs/ear 还在维护吗?

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