# whisper-rs-node

> [![build badge](https://github.com/oyyd/whisper-rs-node/actions/workflows/CI.yml/badge.svg)](https://github.com/oyyd/whisper-rs-node/actions) [![npm version](https://badge.fury.io/js/whisper-rs-node.svg)](https://badge.fury.io/js/whisper-rs-node)

Latest version **0.1.1** (published 2023-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install whisper-rs-node
pnpm add whisper-rs-node
yarn add whisper-rs-node
bun add whisper-rs-node
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-07-30 |
| First published | 2023-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 10 |
| Dependencies | 4 |
| Unpacked size | 41 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | oyyd |

## Links

- npm: https://www.npmjs.com/package/whisper-rs-node
- npm.io page: https://npm.io/package/whisper-rs-node

## Dependencies (4)

- [whisper-rs-node-darwin-x64](https://npm.io/package/whisper-rs-node-darwin-x64.md) 0.1.1
- [whisper-rs-node-darwin-arm64](https://npm.io/package/whisper-rs-node-darwin-arm64.md) 0.1.1
- [whisper-rs-node-linux-x64-gnu](https://npm.io/package/whisper-rs-node-linux-x64-gnu.md) 0.1.1
- [whisper-rs-node-win32-x64-msvc](https://npm.io/package/whisper-rs-node-win32-x64-msvc.md) 0.1.1

## Recent versions

- 0.1.1 (latest) — 2023-07-30
- 0.1.8 (next) — 2023-07-30
- 0.1.7 — 2023-07-30
- 0.1.6 — 2023-07-30
- 0.1.5 — 2023-07-30
- 0.1.4 — 2023-07-30
- 0.1.3 — 2023-07-30
- 0.1.2 — 2023-07-30

## README

# whisper-rs-node

[![build badge](https://github.com/oyyd/whisper-rs-node/actions/workflows/CI.yml/badge.svg)](https://github.com/oyyd/whisper-rs-node/actions)
[![npm version](https://badge.fury.io/js/whisper-rs-node.svg)](https://badge.fury.io/js/whisper-rs-node)

Node.js add-on to [whisper-rs](https://github.com/tazz4843/whisper-rs) (which is bindings to [whisper.cpp](https://github.com/ggerganov/whisper.cpp)).

Features:

- Pre-compiled so that you don't have to prepare compilation environments for these platforms.
- Near native performance as the core part is whisper-rs.

Pre-compiled platforms:

| Platform     | Status |
| ------------ | ------ |
| Mac(arm64)   | ✅     |
| Mac(x64)     | ✅     |
| Windows(x64) | ✅     |
| Linux(x64)   | ✅     |

## Installation

```bash
npm i whisper-rs-node
```

## Download models

Download according to [whisper.cpp/models/README.md](https://github.com/ggerganov/whisper.cpp/tree/master/models#whisper-model-files-in-custom-ggml-format).

## Quick start

```ts
import {
  convertFileBufferToAudioSamples,
  convertIntegerToFloatAudio,
  convertStereoToMonoAudio,
  WhisperContext,
  newGreedyFullParams,
} from 'whisper-rs-node';

// Read model file. You can download model files according to the README.md
const model = fs.readFileSync(
  path.resolve(__dirname, './PATH_TO_YOUR_MODEL.bin')
);

// Create WhipserContext and WhisperState that are used to run the model.
const ctx = new WhisperContext(model);
const state = ctx.createState();

// Read and parse the .wav file.
// You can read the "parseWav" in [example](./examples/audio_transcription.ts).
const { format, samples } = await parseWav(
  path.resolve(__dirname, './PATH_TO_YOUR_WAV_FILE.wav')
);

// Convert the samples into float array which is required by whisper-rs.
let audio = convertIntegerToFloatAudio(samples);

if (format.channels === 2) {
  // Convert into mono audio which is also required by whisper-rs.
  audio = convertStereoToMonoAudio(audio);
} else if (format.channels !== 1) {
  throw new Error('>2 channels unsupported');
}

if (format.sampleRate !== 16000) {
  throw new Error('sample rate must be 16KHz');
}

// Set config in FullParams which would be used in our WhisperState created before.
const fullParams = newGreedyFullParams(0);
fullParams.setNThreads(1);
fullParams.setTranslate(true);
fullParams.setLanguage('en');
fullParams.setPrintProgress(false);
fullParams.setPrintRealtime(false);
fullParams.setPrintSpecial(false);
fullParams.setPrintTimestamps(false);

// Run the model.
state.full(fullParams, audio);

// Get the result and print them.
for (let i = 0; i < state.fullNSegment(); i += 1) {
  console.log(
    `[${state.fullGetSegmentT0(i)}-${state.fullGetSegmentT1(
      i
    )}] ${state.fullGetSegmentText(i)}`
  );
}
```

See [examples/audio_transcription.ts](./examples/audio_transcription.ts) for a detail example.

## LICENSE

MIT

---
_Source: https://npm.io/package/whisper-rs-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
