@descript/kali

中文文档
0.0.7发布于 2021/10/05LGPLTypeScriptESM + CJS零依赖近 30 天下载 1.5万

Kali is used for realtime time-stretching and pitch shifting in Javascript. It can change Tempo and Pitch independently.

原始使用文档
文档目录8 节
  1. Demo
  2. Getting Started
  3. Basic Usage
  4. Documentation
  5. Efficiency
  6. Running Examples
  7. Building
  8. License

Kali

Kali is used for realtime time-stretching and pitch shifting in Javascript. It can change Tempo and Pitch independently.

From Wikipedia:

Time stretching is the process of changing the speed or duration of an audio signal without affecting its pitch. Pitch scaling or pitch shifting is the opposite: the process of changing the pitch without affecting the speed. Similar methods can change speed, pitch, or both at once, in a time-varying way.

Kali uses a WSOLA-like algorithm to do high-quality time stretching in the browser

Demo

Try a demo here.

Getting Started

Get Kali from the releases page.

Kali will be published to npm soon.

Basic Usage

Create a new instance

var kali = new Kali(numChannels);

Set parameters for time stretching. Setting useQuickSearch to true will speed up processing at the expense of some quality. By default, it is set to false. The difference is not noticeable in many cases so try setting it to true if you need more performance.

kali.setup(sampleRate, stretchFactor, useQuickSearch);

Feed Kali some data and tell it to process. dataToInput should be a Float32Array of interlaced samples.

kali.input(dataToInput);
kali.process();

Read data out into a target array. targetArray should be a Float32Array.

var samplesRead = kali.output(targetArray);

Once you're done feeding data, tell Kali to flush its buffers and continue reading data.

kali.flush();

That's it! See Test.ts in the examples folder for a complete example of usage.

If you want to change tempo during stretching, you can call setTempo (with a new stretch factor) while feeding data. This will let you smoothly change between tempos. See Test.ts for an example.

Documentation

For complete documentation, see https://kali.readme.io/docs

Efficiency

By using TypedArrays and views on TypedArrays, Kali operates very efficiently. That said, this is an early release and performance hasn't been optimized as much as possible. Pull requests are welcome!

Running Examples

  • Clone or download this repository
  • Put an mp3 file named test.mp3 in the build/examples directory
  • Start a server in that directory
    • python -m SimpleHTTPServer
  • Open your browser and navigate to the test page
    • e.g. http://localhost:8000/test.html

The developer console will show the progress of the file being stretched. Once the stretch is complete, the slowed-down version will begin playing. This example slows down a song by 4% (so a 125 bpm song will be slowed down to 120 bpm).

To change this (or anything else about the example), edit Test.ts in the examples directory and build as shown below.

Building

npm install

// build examples
webpack --config webpack.config.test.js

// build Kali
webpack

// build minified Kali
webpack -p

License

LGPL

Kali is based on ideas and code from SoundTouch and libsox, both of which are LGPL. Therefore, Kali is also LGPL

版本与发布记录

@descript/kali 共发布 6 个版本,首次发布于 2019/10/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.7latest2021/10/055 年前
0.0.62021/03/055 年前
0.0.52021/02/135 年前
0.0.42020/04/016 年前
0.0.32019/10/297 年前
0.0.22019/10/287 年前

关于 @descript/kali 的常见问题

@descript/kali 是什么?

Kali is used for realtime time-stretching and pitch shifting in Javascript. It can change Tempo and Pitch independently.

如何安装 @descript/kali?

在项目目录运行 npm install @descript/kali,或使用 pnpm add / yarn add / bun add。

@descript/kali 支持 TypeScript 吗?

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

@descript/kali 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@descript/kali 需要什么版本的 Node.js?

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

@descript/kali 可以商用吗?

@descript/kali 使用 LGPL 许可。声明的许可为 LGPL,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@descript/kali 的下载量有多少?

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

@descript/kali 还在维护吗?

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